Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add goal that works with Maven CI Friendly Versions and set property (revision) based on git tag #1071

Open
jimisola opened this issue Apr 24, 2024 · 1 comment

Comments

@jimisola
Copy link

jimisola commented Apr 24, 2024

Maven supports Maven CI Friendly Versions since version 3.5.

It allows the user to set a placeholder

<version>${revision}</version>

that can be replaced from command line using:

e.g.

mvn -Drevision=1.0.0-SNAPSHOT clean package
Our use-case is that you want this revision property (can be configurable) to be set by a Maven plugin using tag information from the scm (typically, git).

The revision property should be set as follows:

note: will be set to variants of nr of commits

  1. if no tags in repo: set to 0.0.1- (e.g. 0.0.1-23) (left-padded due to Maven bug comparing qualifer as a string)
  2. if tags exist
    1. if latest commit is tagged (assume a release): set revision to tag (e.g. 1.0.1)
    2. if it is a previous tag: use the tag, bump patch level, set build number to and add <-SNAPSHOT> (e.g. 0.5.1 -> 0.5.2--SNAPSHOT

That is the basics. I was contemplating writing a plugin for it, but we'll rather so it incorporated in into this plugin.

Build number will be handled correctly by Maven as can be seen here:

java -jar ${MAVEN_HOME}/lib/maven-artifact-3.9.6.jar 1.1 1.2.1-1 1.2.1-1-SNAPSHOT 1.2.1-9 1.3
Display parameters as parsed by Maven (in canonical form and as a list of tokens) and comparison result:
1. 1.1 -> 1.1; tokens: [1, 1]
   1.1 < 1.2.1-1
2. 1.2.1-1 -> 1.2.1-1; tokens: [1, 2, 1, [1]]
   1.2.1-1 > 1.2.1-1-SNAPSHOT
3. 1.2.1-1-SNAPSHOT -> 1.2.1-1-snapshot; tokens: [1, 2, 1, [1, [snapshot]]]
   1.2.1-1-SNAPSHOT < 1.2.1-9
4. 1.2.1-9 -> 1.2.1-9; tokens: [1, 2, 1, [9]]
   1.2.1-9 < 1.3
5. 1.3 -> 1.3; tokens: [1, 3]
@lfvjimisola
Copy link

Would you approve a PR with this functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants