As per the manual, with Maven 3 we're forced to use uniqueSnapshots=true
. This means that each deployment of 1.0-SNAPSHOT
is actually backed by some unique, canonical ID e.g. 1.0-20080207-230803-1
.
As a result, invoking mvn deploy
produces artifacts whose canonical version cannot be determined before the mvn
executable is invoked.
Therefore, if one wishes to invoke any operations on the unique ID generated afterwards, one must try to extract the generated ID from the maven executable after mvn deploy
completes.
Is there any such mechanism to obtain the unique ID?
For example, mvn deploy
will produce the following output:
Uploading: https://oss.sonatype.org/content/repositories/snapshots/io/airlift/slice/0.11-SNAPSHOT/slice-0.11-20150220.165404-2.jar
But there seems to be no way to access the ID 0.11-20150220.165404-2
without parsing the output from Maven.
Example scenario: mvn build results in a new (unique) artifact being pushed to an internal repository manager. After that completes, we wish to push a notification over HTTP to inform some remote application of a new SNAPSHOT version of the application.
Although our repository manager allows us to query for the latest SNAPSHOT version, this is not the same as being able to pass absolute references to specific versions around.
The maven-deploy-plugin does not store the deployment timestamp in system properties.
If you want to take a look at the source code (and maybe make an enhancement request), this deployment timestamp is calculated in class org.apache.maven.artifact.transform.SnapshotTransformation
by the method getDeploymentTimestamp
of the project maven-artifact-manager
.
The final version of the deployed artifact is calculated in method construcVersion
: the SNAPSHOT
is replaced by timestamp-buildNumber
, where timestamp
is the result of getDeploymentTimestamp
and buildNumber
is an increment.
It should be possible to store this constructed version with System.setProperty("something", version)
; and then access it in the pom.xml
with ${something}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With