Using Maven dynamic versioning to release a library

Viewed 2189

Since Maven 3.5.0, it's possible to use some variables inside the <version> tag : https://maven.apache.org/maven-ci-friendly.html

Let's say I have <version>${revision}</version>, in a library project (it produces a jar to be used in other projects, it's not just a web app or a batch application).

When I build and publish my library v1.0.0 (mvn deploy -Drevision=1.0.0-release) the artifact is named "my-library-1.0.0-release.jar", but the pom.xml metadata inside the jar is still at <version>${revision}</version>, are there some use cases where this will make my library unusable ?

EDIT : same question if my library is published in a SNAPSHOT repository and used from there as a dependency to other projects.

2 Answers

There will be problems with using your library as a dependency and publishing to shared artifact repository (e.g. Maven Central) because your pom.xml doesn't match the artifact version. Perhaps some artifact repositories will work (e.g. local Artifactory proxy with custom config) but it's asking for problems.

This is mentioned in the Maven CI Friendly Versions you linked to, under "Install/Deploy" chapter which suggests to use flatten-maven-plugin:

If you like to install or deploy artifacts by using the above setup you have to use the flatten-maven-plugin otherwise you will install/deploy artifacts in your repository which will not be consumable by Maven anymore.

Had this same issue. Solved with this maven extension (in an extension.xml file):

<extensions>
    <!-- this extension ensures ${revision} gets replaced with the proper value in the output pom files-->
    <extension>
      <groupId>fr.jcgay.maven.extension</groupId>
      <artifactId>unique-revision-maven-filtering</artifactId>
      <version>1.2</version>
    </extension>
</extensions>
Related