Using Maven 3.0.4.
I am tasked with providing a corporate parent POM for our organization. My team will provide support for questions or issues developers have when
I stopped using maven-antrun-plugin
and switched to GMaven instead. I can get the info required with a simple POM hierarchy traversal.
<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 calculated property so it may be accessed by child POMs.
Resulting log looks like:
[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
You can achieve property expansion in installed/deployed POM by using a combination of two plugins: - maven-resources-plugin to generate a filtered version of your pom.xml - maven-install-plugin and maven-deploy-plugin, using the install-file and deploy-file mojos, to install/deploy the filtered POM.
This process could for instance be triggered during the releaser process