I can pass two properties A and B to maven via
mvn test -DA=true
or
mvn test -DB=true
If either A or B is defined i want a target to be skipped. I found it was possible when only A was considered like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<target name="anytarget" unless="${A}">
<echo message="This should be skipped if A or B holds" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Now B has to be considered too. Can this be done?
matthias
I would do that with an external build.xml file allowing you to define multiple target combined with antcall and so using one additional dummy target, just to check the second condition.
pom.xml
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<target name="anytarget">
<ant antfile="build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
and the build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="SkipIt" default="main">
<target name="main" unless="${A}">
<antcall target="secondTarget"></antcall>
</target>
<target name="secondTarget" unless="${B}">
<echo>A is not true and B is not true</echo>
</target>
</project>
Alternative solution if you only have 2 conditions: using the <skip> configuration attribute for one condition (i.e. maven stuff) and the unless (i.e. ant stuff) for the other condition:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<skip>${A}</skip>
<target name="anytarget" unless="${B}">
<echo>A is not true and B is not true</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Related
I am writing pom.xml newly and i am trying to Delete a folder already existing and create a new folder.Is there a way to do this? I am looking something like this:
<executions>
<execution>
<configuration>
<tasks>
<if><!-- I need to check if the folder exists and delete->
<delete>
<fileset dir="target/resources"/>
</delete>
</if>
<mkdir dir="target/resources"/>
</tasks>
</configuration>
</execution>
using maven antrun plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<mkdir dir="${project.build.directory}/target/resources" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Another option would be to use exec-plugin
am trying to build a parent pom in Maven which includes a child which is built in ant. I am getting the below exception,
Execution default of goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run failed: A required class was missing while executing org.apache.maven.plugins:maven-antrun-plugin:1.6:run
My code is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<ant dir="SampleJava/projectBuilder.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
and it got resolved with the below code:
--------
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<ant antfile="../SampleJava/projectBuilder.xml" target="makejar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I can pass two properties A and B to maven via
mvn test -DA=true
or
mvn test -DB=true
If either A or B is defined i want a target to be skipped. I found it was possible when only A was considered like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<target name="anytarget" unless="${A}">
<echo message="This should be skipped if A or B holds" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Now B has to be considered too. Can this be done?
matthias
I would do that with an external build.xml file allowing you to define multiple target combined with antcall and so using one additional dummy target, just to check the second condition.
pom.xml
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<target name="anytarget">
<ant antfile="build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
and the build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="SkipIt" default="main">
<target name="main" unless="${A}">
<antcall target="secondTarget"></antcall>
</target>
<target name="secondTarget" unless="${B}">
<echo>A is not true and B is not true</echo>
</target>
</project>
Alternative solution if you only have 2 conditions: using the <skip> configuration attribute for one condition (i.e. maven stuff) and the unless (i.e. ant stuff) for the other condition:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<skip>${A}</skip>
<target name="anytarget" unless="${B}">
<echo>A is not true and B is not true</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I have an xml file called MakeJar.xml in the location ${basedir}/codebase.
On my shell if I have to run that file i used to use the command "ant -f MakeJar.xml".
Now if I have to run this file using pom.xml how can I do that?
I prepared a following pom.xml. But it dosent work!!!
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant antfile="${basedir}/codebase/MakeJar.xml"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Looking at the ant task definition the attribute antfile is described as "the buildfile to use. Defaults to "build.xml". This file is expected to be a filename relative to the dir attribute given."
So you probably have to use:
<ant dir="${project.basedir}" antfile="codebase/MakeJar.xml" />
Also do not forget to specify a <phase> in the plugin section (is missing in your code). The following definition works for me:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<ant
dir="${project.basedir}"
antfile="codebase/MakeJar.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm trying to copy the .jar, created by Maven 3, to another location.
Currently, I'm using Ant's copy task, but Maven simply doesn't copy the file.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>