Deriving maven artifact version from git branch

前端 未结 7 2010
眼角桃花
眼角桃花 2020-12-12 11:07

We have a workflow requirement that essentially mean that we need to have the artifact version of a module externally defined from the current branch in git.

I.e. if

相关标签:
7条回答
  • 2020-12-12 11:40

    Sorry to revive this question and to post very lately another solution but it is possible indeed to change maven version dynamically and to use some git features, a little bit like git describe would do.

    The project that does this is jgitver-maven-plugin (disclaimer; I am the author), it uses jgitver a jgit based library in order to derive maven project version from git information .

    It is very easy to use as a maven extension

    ...
      <build>
          <extensions>
              <extension>
                  <groupId>fr.brouillard.oss</groupId>
                  <artifactId>jgitver-maven-plugin</artifactId>
                  <version>0.1.0</version>
              </extension>
          </extensions>
         ...
      </build>
    ...
    

    The extension can also be used as a plugin extension, and then allows more configuration , for example in case you would not like to use SNAPSHOTS. See the project page for a description of full usage scenarios.

    There is also a gradle plugin available that does more or less the same.


    [edit 1]: answer to Thorbjørn Ravn Andersen comment

    The plugin does not modify the original pom files or the build.gradle files.
    For the maven plugin, modifications are done both in memory in the maven Object Model and written to a temporary file in temp directory. The calculation is based on the git metadata only (tags, commits, ...).
    This non modification allows to not pollute the git history. WHen your are satisfied with a git commit, tag it git tag -a x.y.z and mvn deploy : that's all.
    The version in your project files, is now useless and can be set to 0 for example.

    As of today, and due to IDEA-155733 only recent EAP versions of IntelliJ work with the maven plugin. Eclipse & Netbeans have no problem.


    0 讨论(0)
提交回复
热议问题