Home Navigation

Wednesday 29 November 2017

Maven ant run plugin to execute ant command from maven

The example here for scp (secured copy) using ant in maven. One of the tip for this example you declare your dependency inside the plugin tag.



<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>1.8</version>
<executions>
   <execution>
<id>get-ear-from-nexus</id>
<phase>validate|clean|package|</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<scp file="file_name"
todir=" "
verbose="true" password=" " trust="true"
/>
</target>
</configuration>

</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>

How to add multiple source file for a maven project

You might sometimes encounter a problem working with multiple source directory for a maven project. we are used to work with single source directory eg: src. what if you have src1, src2. src3 ..

Tor resolve this issue you can use maven helper build plugin.

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>build-helper-maven-plugin</artifactId>
   <version>1.9.1</version>
   <executions>
   <execution>
   <id>add-source</id>
   <phase>generate-sources</phase>
   <goals>
<goal>add-source</goal>
   </goals>
   <configuration>
   <sources>
   <source>
${basedir}/src1
   </source>
   <source>
${basedir}/src2
   </source>
   </sources>
   </configuration>
   </execution>
   </executions>
</plugin>

BDD feature/scenario execution via command line

Run all scenarios
      mvn clean test

Run specific feature file
     mvn clean test -Dcucumber.options="src/test/resources/feature/_file_name.feature"

Run specific scenario within feature file
    mvn clean test -Dcucumber.options="src/test/resources/feature/_file_name.feature:7"
    :7 - line# of the desired scenarios

Run specific scenarios within feature file
     mvn clean test -Dcucumber.options="src/test/resources/feature/_file_name.feature:7:20"

Run scenario by tag
     mvn clean test -Dcucumber.options="--tags @test"

Exclude specific tags from execution
    mvn clean test -Dcucumber.options="--tags @reports, -@tags ~@smoke"


Available environment to execute against – Dev, Test
   mvn clean test –Dcucumber.options=”--tags @test” –P test
   mvn clean test –Dcucumber.options=”--tags @test” –P dev