Maven versions plugin: reference a rule.xml from a maven dependency?
Based upon the documentation for the plugin this is possible:
You can provide your ruleset xml file also within a jar, if you want to distribute your ruleset xml as Maven artifact. Therefore you have to declare the containing jar as direct dependency of the versions-maven-plugin and to use classpath as protocol.
I just tried it out and got it to work.
Create a new folder for the new version-rules artifact, as so:
version-rules
|- files
\- version-rules.xml
\- pom.xml
The pom.xml is pretty basic:
...
<artifactId>my-version-rules</artifactId>
<packaging>jar</packaging>
<build>
<defaultGoal>package</defaultGoal>
<resources>
<resource>
<directory>files</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
...
run a mvn install
to install this artifact.
Then, in the other pom, you configure the versions plugin as follows:
...
<build>
...
<pluginManagement>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<rulesUri>classpath:///version-rules.xml</rulesUri>
</configuration>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-version-rules</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
</pluginManagement>
...
</build>
...
This works for me:
<rulesUri>file:///${session.executionRootDirectory}/maven-version-rules.xml</rulesUri>
For the meaning of the variable ${session.executionRootDirectory}
, see
Finding the root directory of a multi module maven reactor project.