org.apache.maven.plugins

Export Maven Properties from Ant Code

I have included the following code in 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> 

Then I refer to ${project.build.directory.portable} to the run project action, but returns as null . Running <echo> in the Ant block shows the correct value. What am I doing wrong?

+4
source share
4 answers

For completeness, the mentioned function was implemented in maven-antrun-plugin in October 2010.

The configuration parameter you are looking for is exportAntProperties .

Usage example:

 <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 an additional note, at the time of publication (2011-10-20), the official documentation of the plugin did not have this document. To get help for the 'versionXYZ' plugin:

 mvn help:describe -Dplugin=org.apache.maven.plugins:maven-antrun-plugin:versionXYZ -Ddetail 
+11
source

Version 1.7 of maven-antrun-plugin helped me pass a property from ant to maven (and from mvn to ant). Some sample code that calculates the md5 checksum of a file and then stores it in a property that mvn accesses later:

 <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 available later with $ {blah.md5db} in the java file.

+3
source

I do not think you can set a property from Ant, which will be visible from Maven. You have to write Mojo.

0
source

From the plugin documentation here :

Try adding the maven prefix so that you have <path location="${maven.project.build.directory}"/> instead

If this does not work, you may need to explicitly override the property yourself:

 <property name="maven.project.build.dir" value="${project.build.directory}"/> <path location="${maven.project.build.directory}"/> 
0
source

Source: https://habr.com/ru/post/1313131/


All Articles