Maven 3: Accessing the Enterprise Root Root Version

Using Maven 3.0.4.

I have been tasked with providing the corporate parent POM for our organization. My team will support questions or concerns that developers have when using this POM. Often they attach a build log to a support ticket. So, I want my corporate POM to replicate the corporate parent version to the console with any assembly. I use the antrun plugin for this.

<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>echo-build-environment</id> <phase>validate</phase> <goals><goal>run</goal></goals> <configuration> <target> <echo level="info" message="Maven ${maven.version}" taskname="Version" /> <echo level="info" message="Corporate POMs ${want.the.version.here}" taskname="Version" /> .... </target> 

Trick, I don’t know how many β€œlevels” of POM inheritance can occur between the corporate parent and the POM used in the assembly. We could have an inheritance structure something like this:

 corporate-parent team-parent application-parent child-module 

Or simply:

 corporate-parent a-simple-library 

I can not answer ${project.version} , because it will be a version of the current (child) project. I cannot use ${project.parent.version} because I have no idea how many levels of inheritance there can be. I tried to define the <corporate.pom.version> property, hard-coded for the corporate version of POM, however, when I release my corporate POM, the release plugin does not know to update this property (which makes sense, this is not a dependency version, it's just a property version of the version can not know to update it).

Ideally, I would like to get the version of a specific POM directly through a property, something like ${some.groupId.corporate-parent.version} . Is there anything similar?

If not, is there a way during release to update the POM property with releaseVersion released project?

I could go back to the rough way of manually editing a property before each version. My teammates would not appreciate this approach.

I hope that I do not need to write a custom plugin to do something that at first glance did not seem complicated.

+4
source share
2 answers

I stopped using maven-antrun-plugin and switched to GMaven instead . I can get the information needed with a simple traversal of the POM hierarchy.

 <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>groovy-maven-plugin</artifactId> <version>2.0</version> <executions> <execution> <id>echo-build-environment</id> <phase>validate</phase> <goals> <goal>execute</goal> </goals> <configuration> <source> <![CDATA[ def rootPom = project; while (rootPom.parent != null) { rootPom = rootPom.parent; } project.properties.setProperty('root.pom.version', rootPom.version); log.info(" Maven Home: " + project.properties['maven.home']); log.info(" Java Home: " + project.properties['java.home']); log.info(" Built By User: " + project.properties['user.name']); log.info("Corp POM Version: " + rootPom.version); ]]> </source> </configuration> </execution> </executions> </plugin> 

The project.properties.setProperty part stores the computed property, so child POMs can access it.

The resulting log is as follows:

 [INFO] Maven Home: c:\dev\maven\apache-maven-3.0.4 [INFO] Java Home: c:\Program Files\Java\jdk1.7.0_13\jre [INFO] Built By User: user944849 [INFO] Corp POM Version: 0.26-SNAPSHOT 
+2
source

You can achieve property extensions in the installed / deployed POM using a combination of two plugins: - maven-resources-plugin to create a filtered version of your pom.xml - maven-install-plugin and maven-deploy-plugin using the -file and mojos installation for deployment, to install / deploy filtered POM.

This process may, for example, be started during the release process.

0
source

All Articles