Reputation: 13245
Plugin version: 2.0
I am trying to use the maven-release-plugin to set the version of the parent POM and all modules.
Using the following parent POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.mycompany</groupId>
<artifactId>myProject</artifactId>
<version>latest-SNAPSHOT</version>
<packaging>pom</packaging>
<name>My Project</name>
<modules>
<module>../../subPom1</module>
<module>../../subPom2</module>
<module>../../subPom3</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>clean</phase>
<id>set-release-versions</id>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When running mvn clean install -DskipTests -Pdeploy
, the configuration to run the plugin on the clean phase is totally ignored and the build is made using the value "latest-SNAPSHOT".
I was expecting it to pick up the value "1.1.8" from the plugin configuration.
Each child POM is equivalent to:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>uk.co.mycompany</groupId>
<artifactId>myProject</artifactId>
<version>latest-SNAPSHOT</version>
<relativePath>../../System/build/parentPom.xml</relativePath>
</parent>
...
</project>
Why is the configuration ignored?
Edit #1: Filesystem structure as requested:
/
|- system
| |
| |- build
| |
| |-parentPOM file
|
|- business
| |
| | - childPOM1
| | - childPOM2
|- client
| | - childPOM3
| | - childPOM4
Ignore the .../... in the SSCCE - I have obfuscated the true values to describe the problem generically.
Edit #2: I have moved the definition to <pluginManagement>
as advised but the problem remains the same (not using plugin, no feedback to console):
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Upvotes: 1
Views: 3401
Reputation: 11470
You forgot to set the goal of the plugin. You configured the parameter needed for the update-versions goal but you told maven only to execute the plugin in the clean phase, but not which goal of the plugin. So it does nothing at all.
Check the maven log when you try a mvn clean it should only show:
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test ---
When you change your config to:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>clean</phase>
<id>set-release-versions</id>
<goals><goal>update-versions</goal></goals>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The goal update-versions is called in the clean phase of maven.
[INFO] --- maven-release-plugin:2.0:update-versions (set-release-versions) @ bdd ---
Not sure if this will solve all your problems but this will force maven to execute the plugin in the clean phase like expected.
However the release plugin needs a lot of special settings (like a scm connection) when used for only changing the version. So I suggest to use the versions-maven-plugin
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<goals>
<goal>set</goal>
</goals>
<phase>clean</phase>
<configuration>
<newVersion>1.1.8</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Upvotes: 2
Reputation: 13245
In the end, I gave up.
That Stack Overflow et all is littered with unanswered questions just like this one, and that the plugin documentation fails to provide usage examples in POM format, tells me everything that I need to know about this plugin.
My workaround was to set the parent POM's version to "latest-SNAPSHOT" and introduce a property called <myproject.release.version>,
which I used everywhere that I wanted to print the release number.
In particular, I wanted to print the release number in the WAR file's manifest. I did so as below:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>${myproject.release.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
<filters>
<filter>${project.parent.basedir}/filter/${webapp.filter}.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Using the above configuration, I drop the release number, as a Maven property, into my manifest.
In my application, I pick it up from there and draw it on the screen.
Upvotes: 1