A Maven plugin to get rid of SNAPSHOT versions and automatically update artifact versions with each build if anything changes. Such a change can be a scm commit since the last build or a newly available upstream dependency version within a configured range.
When working on a huge project with hundreds of Maven artifacts depending on each other, dealing with SNAPSHOT versions really becomes unhandy. The main reasons are:
The algorithm works as follows:
The generated artifact versions consist of a "base version", which can be configured, and the build timestamp or revision id (SVN only) as a qualifier. Examples:
The plugin can be added to a separate (POM-) project or your main aggregator project. Like this:
<build>
<plugins>
<plugin>
<groupId>at.nonblocking</groupId>
<artifactId>nonsnapshot-maven-plugin</artifactId>
<version>4.0.1</version>
<configuration>
<baseVersion>1.2.3</baseVersion>
<scmType>SVN</scmType>
<!-- <scmType>GIT</scmType> -->
<scmUser>${scmUser}</scmUser>
<scmPassword>${scmPassword}</scmPassword>
<useSvnRevisionQualifier>true</useSvnRevisionQualifier>
<deferPomCommit>true</deferPomCommit>
<generateIncrementalBuildScripts>true</generateIncrementalBuildScripts>
<generateChangedProjectsPropertyFile>true</generateChangedProjectsPropertyFile>
<dontFailOnCommit>false</dontFailOnCommit>
<dontFailOnUpstreamVersionResolution>false</dontFailOnUpstreamVersionResolution>
<upstreamDependencies>
<upstreamDependency>at.nonblocking:*:LATEST</upstreamDependency>
<!-- Examples -->
<!-- <upstreamDependency>at.nonblocking:*:2.10</upstreamDependency> -->
<!-- <upstreamDependency>at.nonblocking:test-test2:2.10.3</upstreamDependency>-->
<!-- <upstreamDependency>at.nonblocking:test-*:LATEST</upstreamDependency>-->
</upstreamDependencies>
</configuration>
</plugin>
</plugins>
</build>
The upstream dependency list is processed in order of their definition and the first match is taken. That allows it to define an exceptions from a wildcard rule like this:
<upstreamDependency>at.nonblocking:test:2.3.4</upstreamDependency>
<upstreamDependency>at.nonblocking:*:LATEST</upstreamDependency>
The following goals are available:
A fully automatized auto-release is of course only possible if you use this plugin within a CI server (e.g. Jenkins).
First add the following optional configuration parameter:
<deferPomCommit>true</deferPomCommit>
Then configure the job on your CI server like this:
On Jenkins you can use pre-build and post-build steps for #2 and #5.
This configuration guarantees that the module versions in the dependencies section of a POM file are always available from the remote Maven repository. (And so the developers no longer need all the Java projects in their workspace.)
For Continuous Deployment just create a new release (POM-) module which includes all your deployment modules in the dependencies section.
For example:
<dependencies>
<dependency>
<groupId>my.domain</groupId>
<artifactId>webapp1</artifactId>
<version>1.0.12-4567</version>
<type>war</type>
</dependency>
<dependency>
<groupId>my.domain</groupId>
<artifactId>webapp2</artifactId>
<version>1.0.12-4555</version>
<type>war</type>
</dependency>
</dependencies>
Since the dependency versions are rewritten with each plugin execution, they will always point to the latest version. You can now use the maven-dependency-plugin or the maven-assembly-plugin together with ant to copy all your deployment artifact to the server.
Licensed under the Apache License, Version 2.0.