Maven Git Autoversioning

Automatically determine the artifact version from git tags.

License

License

Categories

Categories

Maven Build Tools Git Development Tools Version Controls Auto Application Layer Libs Code Generators
GroupId

GroupId

de.pal-software.tools
ArtifactId

ArtifactId

maven-git-autover
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Maven Git Autoversioning
Automatically determine the artifact version from git tags.
Project URL

Project URL

https://github.com/edipal/maven-git-autover
Source Code Management

Source Code Management

https://github.com/edipal/maven-git-autover

Download maven-git-autover

How to add to project

<!-- https://jarcasting.com/artifacts/de.pal-software.tools/maven-git-autover/ -->
<dependency>
    <groupId>de.pal-software.tools</groupId>
    <artifactId>maven-git-autover</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/de.pal-software.tools/maven-git-autover/
implementation 'de.pal-software.tools:maven-git-autover:1.0.1'
// https://jarcasting.com/artifacts/de.pal-software.tools/maven-git-autover/
implementation ("de.pal-software.tools:maven-git-autover:1.0.1")
'de.pal-software.tools:maven-git-autover:jar:1.0.1'
<dependency org="de.pal-software.tools" name="maven-git-autover" rev="1.0.1">
  <artifact name="maven-git-autover" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.pal-software.tools', module='maven-git-autover', version='1.0.1')
)
libraryDependencies += "de.pal-software.tools" % "maven-git-autover" % "1.0.1"
[de.pal-software.tools/maven-git-autover "1.0.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.eclipse.jgit : org.eclipse.jgit jar 4.11.0.201803080745-r
org.glassfish.jaxb : jaxb-runtime jar 2.3.0
javax.activation : activation jar 1.1.1
javax.xml.bind : jaxb-api jar 2.3.0

provided (1)

Group / Artifact Type Version
org.apache.maven : maven-core jar 3.5.0

test (2)

Group / Artifact Type Version
org.eclipse.jgit : org.eclipse.jgit.junit jar 4.11.0.201803080745-r
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Introduction

There are cases when it is advantageous that the version is calculated instead of specified in the pom. This is a Maven plugin that can automatically calculate a version based on Git tags. It should be registered as a Maven extension .mvn/extensions.xml file.

Git tag types

In git there are two types of tags: lightweight and annotated. Annotated tags are usually used to mark releases (they have a comment/description) and lightweight tags in other cases.

Configuration

How the plugin calculates the version is configurable. The version will be calculated only for artifacts that have the version 0.0.0-SNAPSHOT. A configuration has the following parameters:

  • versionTagRegex: This is used to determine what tags should be considered version tags
  • includeGroupIds: Only artifacts in this group ids will be processed. When no such group is specified artifacts from all groups ids will be processed
  • autoverBranchConfigs: The branch configurations
    • nameRegex: This is used to determine the branches that should use this configuration
    • stopOn: the stop on setting to be used by branches that match the above pattern possible values
      • ON_FIRST: It will use the first annotation that it will find (regardles of the type)
      • ON_FIRST_ANN: It will use the first annotated branch that it will find
      • ON_FIRST_LIGHT: It will use the first light branch that it will find The branch name is checked against the configured branches in the order from the configuration file and it stops on the first that matches.

How the version is calculated

The version is calculated based on the configuration. The plugin will look to the git history and "walk back" from current commit until it finds the first tag of the type configured for the branch and if the tag found is:

  • an annotated tag: it will calculate the next version as the next minor version and add SNAPSHOT (For ex: when it finds tag 2.0.1, it will calculate the version as 2.0.2-SNAPSHOT)
  • a lightweight tag: the version will be equal to the lightweight tag (For ex: when it finds tag 2.1.0-SNAPSHOT, it will calculate the version as 2.1.0-SNAPSHOT)

Default configuration

The plugin has the following default configuration.

  • versionTagRegex - [0-9]+\.[0-9]+\.([0-9]+)(-SNAPSHOT)?
  • includeGroupIds - empty (all groups will be considered)
  • autoverBranchConfigs
    • master - ON_FIRST_LIGHT
    • release/.* - ON_FIRST_ANN
    • feature/([A-Z0-9]+-[0-9]+)-.* - ON_FIRST_LIGHT
    • bugfix/([A-Z0-9]+-[0-9]+)-.* - ON_FIRST_ANN
    • (PR-\d+) - ON_FIRST (for jenkins)
    • .* - ON_FIRST

Use non default configuration

If the default configuration is not OK for a certain maven module, a different configuration can be specified. This custom configuration file should have the name git.autover.conf.xml and be placed in the .mvn folder of the module.

How to disable it

The plugin execution can be disabled using -Dautover.disable=true. This way the version specified in the pom file will be used. Also one could disable only the pom changes using -Dautover.disable.pom.change=true.

Versions

Version
1.0.1
1.0.0