I've embedded the following code within my POM:
<plugin name="test">
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<tasks>
<pathconvert targetos="unix" property="project.build.directory.portable">
<path location="${project.build.directory}"/>
</pathconvert>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I then reference ${project.build.directory.portable}
from the run project
action but it comes back as null
. Executing <echo>
within the Ant block shows the correct value. What am I doing wrong?
For completeness, the mentioned feature was implemented in the maven-antrun-plugin
in October 2010.
The configuration parameter you are looking for is exportAntProperties
.
Example of use:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7-SNAPSHOT</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec outputproperty="svnversion"
executable="svnversion">
<arg value=".." />
</exec>
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
</plugin>
As a side note, at the time of this post (2011-10-20), the official plugin documentation didn't have this option documented. To get the help for 'versionXYZ' of the plugin:
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-antrun-plugin:versionXYZ -Ddetail
The version 1.7 of the maven-antrun-plugin worked for me to pass a property from ant to maven (and from mvn to ant). Some sample code that calculates an md5 checksum of a file and later stores it into a property that is accessed by mvn at a later time:
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>ant-md5</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="outputDir" value="${project.build.outputDirectory}"/>
<property name="sourceDir" value="${project.build.sourceDirectory}"/>
<checksum file="${sourceDir}/com/blah/db/blah.java" property="blah.md5db"/>
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
The property is accessible in later with ${blah.md5db} in a java file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With