Home > Mobile >  Using git commit count and commit hash as version in artifact generated by Maven
Using git commit count and commit hash as version in artifact generated by Maven

Time:02-18

I've seen so many (answered) questions about using git commit hash as suffix in the version generated when releasing library. But I can't find any link that describe using commit count in combination of commit hash.

The version format that I'm looking for is <commit count>-<commit hash> for Java library built using Maven.

Is there any existing Maven plugin that can generate that format?

CodePudding user response:

Add this to your maven file:

<build>
<finalName>${project.name}-${git.total.commit.count}-${git.commit.id.abbrev}</finalName>
<plugins>
    <plugin>
        <groupId>io.github.git-commit-id</groupId>
        <artifactId>git-commit-id-maven-plugin</artifactId>
        <version>5.0.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>revision</goal>
                </goals>
                <phase>initialize</phase>
            </execution>
        </executions>
    </plugin>
</plugins>
</build>

See git-commit-id-maven-plugin.

Once again, I want to point out that this is a bad library version and I wouldn't be happy consuming it. You talk about a single git repo in your company but that's irrelevant as it says nothing about the consumers of your library. You're probably building an "application" (no consumers) while referring to it as a "library".

  • Related