Giter Site home page Giter Site logo

qoomon / maven-git-versioning-extension Goto Github PK

View Code? Open in Web Editor NEW
292.0 10.0 80.0 1.38 MB

This extension will set project version, based on current Git branch or tag.

License: GNU General Public License v3.0

Java 100.00%
git versioning tag branch repository generated maven-plugin maven-extension maven gradle

maven-git-versioning-extension's Introduction

Maven Git Versioning Extension Sparkline

Maven Central Changelog Build Workflow LGTM Grade

ℹ Also available as Gradle Plugin

Example

This extension can virtually set project version and properties, based on current Git status

No POM files will be modified, version and properties are modified in memory only

Requirements

  • ⚠️ minimal required java version is 11
  • ⚠️ minimal required maven version is 3.6.3

Usage

⚠️ If you're using IntelliJ have a look at IntelliJ Setup Instructions

Add Extension to Maven Project

create or update ${rootProjectDir}/.mvn/extensions.xml file

<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">

    <extension>
        <groupId>me.qoomon</groupId>
        <artifactId>maven-git-versioning-extension</artifactId>
        <version>9.6.6</version>
    </extension>

</extensions>

Configure Extension

ℹ Consider CI/CD section when running this extension in a CI/CD environment

Create ${rootProjectDir}/.mvn/maven-git-versioning-extension.xml.

You can configure the version and properties adjustments for specific branches and tags.

Example: maven-git-versioning-extension.xml

<configuration xmlns="https://github.com/qoomon/maven-git-versioning-extension"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="https://github.com/qoomon/maven-git-versioning-extension https://qoomon.github.io/maven-git-versioning-extension/configuration-9.4.0.xsd">

    <refs>
        <ref type="branch">
            <pattern>.+</pattern>
            <version>${ref}-SNAPSHOT</version>
            <properties>
                <foo>${ref}</foo>
            </properties>
        </ref>

        <ref type="tag">
            <pattern><![CDATA[v(?<version>.*)]]></pattern>
            <version>${ref.version}</version>
        </ref>
    </refs>

    <!-- optional fallback configuration in case of no matching ref configuration-->
    <rev>
        <version>${commit}</version>
    </rev>

</configuration>

Configuration Elements

  • <disable> global disable(true)/enable(false) extension, default is false.

  • <projectVersionPattern> An arbitrary regex to match project version, matching groups can be used as Format Placeholders (has to be a full match pattern)

  • <describeTagPattern> An arbitrary regex to match tag names for git describe command

    • has to be a full match pattern e.g. v(.+), default is .*
  • <describeTagFirstParent> Enable(true) or disable(false) following only the first parent in a merge commit

    • default is true
  • <updatePom> Enable(true)/disable(false) version and properties update in original pom file, default is false

  • <refs considerTagsOnBranches="BOOLEAN"> List of ref configurations, ordered by priority. First matching configuration will be used.

    • considerTagsOnBranches By default, tags pointing at current commit will be ignored if HEAD is attached to a branch.

    • If this option is true tags will always be taken into account.

    • <ref type="TYPE"> specific ref patch definition.

      • required type Ref type indicates which kind of ref will be matched against pattern, can be branch or tag

      • <pattern> An arbitrary regex to match ref names

        • has to be a full match pattern e.g. main or feature/.+

      • <describeTagPattern> An arbitrary regex to match tag names for git describe command

        • has to be a full match pattern e.g. v.+)
        • will override global <describeTagPattern> value
      • <describeTagFirstParent> Enable(true) or disable(false) following only the first parent in a merge commit

        • default is true

      • <version> The new version format, see Format Placeholders

      • <properties>

        • <name>value</name> A property definition to update the value of a property.
      • <userProperties>

        • <name>value</name> A property definition to add a user property to the maven session, active during the build. UserProperties with the same name of a property in the pom or this configuration file will take precedence as that is how maven handles user properties.
        <userProperties>
            <test.property>${ref}</test.property>
        </userProperties>
      • <updatePom> Enable(true) or disable(false) version and properties update in original pom file

        • will override global <updatePom> value
  • <rev> Rev configuration will be used if no ref configuration is matching current git situation.

    • same as <ref> configuration, except type attribute and <pattern> element.
  • <relatedProjects> Add external projects as related project to update their versions as well.

    <relatedProjects>
        <project>
            <groupId>me.qoomon</groupId>
            <artifactId>base</artifactId>
        </project>
    </relatedProjects>

Format Placeholders

….slug placeholders means all / characters will be replaced by -.

ℹ Final version will be slugified automatically, so no need to use ${….slug} placeholders in <version> format.

ℹ define placeholder default value (placeholder is not defined) like this ${name:-DEFAULT_VALUE}
e.g ${env.BUILD_NUMBER:-0} or ${env.BUILD_NUMBER:-local}

ℹ define placeholder overwrite value (placeholder is defined) like this ${name:+OVERWRITE_VALUE}
e.g ${dirty:-SNAPSHOT} resolves to -SNAPSHOT instead of -DIRTY

Placeholders
  • ${env.VARIABLE} Value of environment variable VARIABLE

  • ${property.name} Value of commandline property -Dname=value

  • ${version} <version> set in pom.xml e.g. '1.2.3-SNAPSHOT'

    • ${version.core} the core version component of ${version} e.g. '1.2.3'
    • ${version.major} the major version component of ${version} e.g. '1'
      • ${version.major.next} the ${version.major} increased by 1 e.g. '2'
    • ${version.minor} the minor version component of ${version} e.g. '2'
      • ${version.minor.next} the ${version.minor} increased by 1 e.g. '3'
    • ${version.patch} the patch version component of ${version} e.g. '3'
      • ${version.patch.next} the ${version.patch} increased by 1 e.g. '4'
    • ${version.label} the version label of ${version} e.g. 'SNAPSHOT'
      • ${version.label.prefixed} like ${version.label} with label separator e.g. '-SNAPSHOT'
  • Project Version Pattern Groups

    • Content of regex groups in <projectVersionPattern> can be addressed like this:
    • ${version.GROUP_NAME}
    • ${version.GROUP_INDEX}
    • Named Group Example
      <configuration>
        <projectVersionPattern><![CDATA[^.+-(?<environment>.+)-SNAPSHOT$]]></projectVersionPattern>
      
        <refs>
          <ref type="branch">
            <version>${version.environment}-SNAPSHOT</version>
          </ref>
        </refs>
      </configuration>

  • ${ref} ${ref.slug} ref name (branch or tag name or commit hash)

  • Ref Pattern Groups

    • Content of regex groups in <ref><pattern> can be addressed like this:
    • ${ref.GROUP_NAME} ${ref.GROUP_NAME.slug}
    • ${ref.GROUP_INDEX} ${ref.GROUP_INDEX.slug}
    • Named Group Example
      <ref type="branch">
          <pattern><![CDATA[feature/(?<feature>.+)]]></pattern>
          <version>${ref.feature}-SNAPSHOT</version>
      </ref>

  • ${commit} commit hash '0fc20459a8eceb2c4abb9bf0af45a6e8af17b94b'

  • ${commit.short} commit hash (7 characters) e.g. '0fc2045'

  • ${commit.timestamp} commit timestamp (epoch seconds) e.g. '1560694278'

  • ${commit.timestamp.year} commit year e.g. '2021'

  • ${commit.timestamp.year.2digit} 2-digit commit year.g. '21'

  • ${commit.timestamp.month} commit month of year e.g. '12'

  • ${commit.timestamp.day} commit day of month e.g. '23'

  • ${commit.timestamp.hour} commit hour of day (24h)e.g. '13'

  • ${commit.timestamp.minute} commit minute of hour e.g. '59'

  • ${commit.timestamp.second} commit second of minute e.g. '30'

  • ${commit.timestamp.datetime} commit timestamp formatted as yyyyMMdd.HHmmsse.g. '20190616.161442'

  • ${build.timestamp} maven-build-timestamp (epoch seconds) e.g. '1560694278'

  • ${build.timestamp.year} maven-build-timestamp year e.g. '2021'

  • ${build.timestamp.year.2digit} 2-digit maven-build-timestamp year.g. '21'

  • ${build.timestamp.month} maven-build-timestamp month of year e.g. '12'

  • ${build.timestamp.day} maven-build-timestamp day of month e.g. '23'

  • ${build.timestamp.hour} maven-build-timestamp hour of day (24h)e.g. '13'

  • ${build.timestamp.minute} maven-build-timestamp minute of hour e.g. '59'

  • ${build.timestamp.second} maven-build-timestamp second of minute e.g. '30'

  • ${build.timestamp.datetime} maven-build-timestamp formatted as yyyyMMdd.HHmmsse.g. '20190616.161442'

  • ${describe} Will resolve to git describe output

  • ${describe.distance} The distance count to last matching tag

  • ${describe.distance.snapshot} Empty string on matching tag, -SNAPSHOT if describe.distance > 0

  • ${describe.tag} The matching tag of git describe

    • ${describe.tag.version} the tag version determined by regex (?<version>(?<core>(?<major>\d+)(?:\.(?<minor>\d+)(?:\.(?<patch>\d+))?)?)(?:-(?<label>.*))?)
      • ${describe.tag.version.core} the core version component of ${describe.tag.version} e.g. '1.2.3'
      • ${describe.tag.version.major} the major version component of ${describe.tag.version} e.g. '1'
        • ${describe.tag.version.major.next} the ${describe.tag.version.major} increased by 1 e.g. '2'
      • ${describe.tag.version.minor} the minor version component of ${describe.tag.version} e.g. '2'
        • ${describe.tag.version.minor.next} the ${describe.tag.version.minor} increased by 1 e.g. '3'
      • ${describe.tag.version.patch} the patch version component of ${describe.tag.version} e.g. '3'
        • ${describe.tag.version.patch.next} the ${describe.tag.version.patch} increased by 1 e.g. '4'
        • ${describe.tag.version.patch.plus.describe.distance} the ${describe.tag.version.patch} increased by ${describe.distance} e.g. '2'
        • ${describe.tag.version.patch.next.plus.describe.distance} the ${describe.tag.version.patch.next} increased by ${describe.distance} e.g. '3'
      • ${describe.tag.version.label} the label version component of ${describe.tag.version} e.g. 'SNAPSHOT'
        • ${describe.tag.version.label.next} the ${describe.tag.version.label} converted to an integer and increased by 1 e.g. '6'
        • ${describe.tag.version.label.plus.describe.distance} the ${describe.tag.version.label} increased by ${describe.distance} e.g. '2'
        • ${describe.tag.version.label.next.plus.describe.distance} the ${describe.tag.version.label.next} increased by ${describe.distance} e.g. '3'
  • Describe Tag Pattern Groups

    • Content of regex groups in <describeTagPattern> can be addressed like this:
    • ${describe.tag.GROUP_NAME} ${describe.tag.GROUP_NAME.slug}
    • ${describe.tag.GROUP_INDEX} ${describe.tag.GROUP_INDEX.slug}
    • Named Group Example
      <ref type="branch">
          <pattern>main</pattern>
          <describeTagPattern><![CDATA[v(?<name>.*)]]></describeTagPattern>
          <version>${describe.tag.name}-SNAPSHOT</version>
      </ref>

  • ${dirty} If repository has untracked files or uncommitted changes this placeholder will resolve to -DIRTY, otherwise it will resolve to an empty string.

    • ℹ May lead to performance issue on very large projects (10,000+ files)
  • ${dirty.snapshot} Like ${dirty}, but will resolve to -SNAPSHOT

  • ${value} Original value of matching property (Only available within property format)

Parameters & Environment Variables

  • Disable Extension

    • Environment Variables
    • export VERSIONING_DISABLE=true
    • Command Line Parameters
    • mvn … -Dversioning.disable
  • Provide branch or tag name

    • Environment Variables
    • export VERSIONING_GIT_REF=$PROVIDED_REF e.g. refs/heads/main, refs/tags/v1.0.0 or refs/pull/1000/head
    • export VERSIONING_GIT_BRANCH=$PROVIDED_BRANCH_NAME e.g. main or refs/heads/main
    • export VERSIONING_GIT_TAG=$PROVIDED_TAG_NAME e.g. v1.0.0 or refs/tags/v1.0.0
    • Command Line Parameters
    • mvn … -Dgit.ref=$PROVIDED_REF
    • mvn … -Dgit.branch=$PROVIDED_BRANCH_NAME
    • mvn … -Dgit.tag=$PROVIDED_TAG_NAME

    ℹ Especially useful for CI builds see Miscellaneous Hints

  • Update pom.xml

    • Environment Variables
    • export VERSIONING_UPDATE_POM=true
    • Command Line Parameters
    • mvn … -Dversioning.updatePom

Provided Project Properties

  • git.worktree absolute path of git worktree directory

IDE Setup

IntelliJ - Multi Modules Projects

For a flawless experience you need to disable this extension during project import, otherwise you'll get errors for modules depending on another module.
To disable this extension during import add following Maven Importer VM options (Preferences > Build, Execution, Deployment > Build Tools > Maven > Importing > VM options for importer) -Dversioning.disable=true

Related Issues

CI/CD Setup

Most CI/CD systems do checkouts in a detached HEAD state so no branch information is available, however they provide environment variables with this information. You can provide those, by using Parameters & Environment Variables.

Native Support

  • GitHub Actions: if $GITHUB_ACTIONS == true, GITHUB_REF is considered
  • GitLab CI: if $GITLAB_CI == true, CI_COMMIT_BRANCH, CI_COMMIT_TAG and CI_MERGE_REQUEST_SOURCE_BRANCH_NAME are considered
  • Circle CI: if $CIRCLECI == true, CIRCLE_BRANCH and CIRCLE_TAG are considered
  • Jenkins: if JENKINS_HOME is set, BRANCH_NAME and TAG_NAME are considered

Manual Setup

Set following environment variables before running your mvn command

export VERSIONING_GIT_REF=$PROVIDED_REF;

$PROVIDED_REF value examples: refs/heads/main, refs/tags/v1.0.0 or refs/pull/1000/head

or

export VERSIONING_GIT_BRANCH=$PROVIDED_BRANCH;
export VERSIONING_GIT_TAG=$PROVIDED_TAG;

$PROVIDED_BRANCH value examples: main, refs/heads/main or refs/pull/1000/head

$PROVIDED_TAG value examples: v1.0.0 or refs/tags/v1.0.0


Miscellaneous Hints

Commandline To Print Project Version

mvn help:evaluate -Dexpression=project.version -q -DforceStdout

Reproducible builds

The maven reproducible builds feature can be easily supported with this extension e.g.

<ref type="branch">
  <pattern>.+</pattern>
  <properties>
    <project.build.outputTimestamp>${commit.timestamp}</project.build.outputTimestamp>
  </properties>
</ref>

Build & Release

gpg --import private.key
gpg --list-keys
  ./mvnw verify
  # Publishes this plugin to local Maven
  ./mvnw install
  # Run integration tests after install, 
  # integration tests will run with LATEST version of extension installed
  ./mvnw failsafe:integration-test
  # Publishes this plugin to OSS Nexus.
  GPG_TTY=$(tty) ./mvnw clean deploy -P release -Dgpg.keyname=???
Debug
mvn help:evaluate -Dexpression=project.version -Dorg.slf4j.simpleLogger.log.me.qoomon.maven.gitversioning=debug

maven-git-versioning-extension's People

Contributors

a-grasso avatar andreas-dornhof avatar bimeche avatar cboehme avatar cemo avatar chris-mac avatar danchr avatar dependabot[bot] avatar dissem avatar florianli avatar jeremy-im avatar jezprime-trp avatar jschneider avatar jycr avatar l3ender avatar ls-urs-keller avatar marcelcanter avatar maxstreese avatar mcfoggy avatar melozzola avatar mruzicka avatar olivergondza avatar pdkyas avatar qoomon avatar reitzmichnicht avatar saschaschwarz avatar tisoft avatar wonno avatar xeagle2 avatar zulkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maven-git-versioning-extension's Issues

Is there IDE-support?

Hello out there,
thanks a lot for providing this extension!

I have a multi-module-setup with a lot of modules here with the configuration of the extension at top-level. Modules get installed/deployed with "module-1.2.3-feature-abc-SNAPSHOT" instead of the default branch name "module-1.2.3-SNAPSHOT".
My use-case now is that I want to open only some of the modules in the IDE (here Eclipse with m2e). The rest of the modules should be resolved from the local repository.
Instead of resolving the module branch specific ("module-1.2.3-feature-abc-SNAPSHOT"), Eclipse seems to look for "module-1.2.3-SNAPSHOT".

Is IDE-support given in general and should I search for a problem in my setup?
The only solution I see is to use the "updatePom" option, which will alter all pom-files presumably causes merge conflicts when the branches get merged back.

Version release number in tag loses digit

I am integrating maven-git-versioning-extension and am facing the following issue. My project's pom file has the following version: <version>1.0.0-SNAPSHOT</version>

However, when I try and release, the version that is generated by the extension is 1.0 instead of 1.0.0, and the incremented version is 1.1 instead of 1.0.1:

$ mvn release:prepare -DdryRun=true -Dresume=false -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] --- maven-git-versioning-extension:1.1.0 ---
[INFO] common-lib:1.0.0-SNAPSHOT -> version: single-artifact-maven-builds-SNAPSHOT
[INFO]
[INFO] ------------------------< org.company:common-lib >------------------------
[INFO] Building common-lib single-artifact-maven-builds-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.5.3:prepare (default-cli) @ common-lib ---
[INFO] Verifying that there are no local modifications...
[INFO]   ignoring changes on: **\pom.xml.next, **\release.properties, **\pom.xml.branch, **\pom.xml.tag, **\pom.xml.backup, **\pom.xml.releaseBackup
[INFO] Executing: cmd.exe /X /C "git rev-parse --show-toplevel"
[INFO] Working directory: C:\Repositories\common-lib
[INFO] Executing: cmd.exe /X /C "git status --porcelain ."
[INFO] Working directory: C:\Repositories\common-lib
[WARNING] Ignoring unrecognized line: ?? .mvn/maven-git-versioning-extension.xml
[WARNING] Ignoring unrecognized line: ?? pom.xml.releaseBackup
[WARNING] Ignoring unrecognized line: ?? release.properties
[INFO] Checking dependencies and plugins for snapshots ...
What is the release version for "common-lib"? (org.company:common-lib) 1.0: :
What is SCM release tag or label for "common-lib"? (org.company:common-lib) common-lib-1.0: :
What is the new development version for "common-lib"? (org.company:common-lib) 1.1-SNAPSHOT: :

My maven-git-versioning-extension.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<branches>
		<branch>
			<pattern>master</pattern>
			<versionFormat>${version.release}</versionFormat>
		</branch>
		<branch>
			<pattern>artifact/.*</pattern>
			<prefix>artifact/</prefix>
			<versionFormat>${version.release}-${branch}-SNAPSHOT</versionFormat>
		</branch>
	</branches>
	<tags>
		<tag>
			<pattern>.*</pattern>
			<versionFormat>${version.release}</versionFormat>
		</tag>
	</tags>
</configuration>

If I disable the extension via the command line argument, I see the correct versions:

$ mvn release:prepare -DdryRun=true -Dresume=false -DgitVersioning=false -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] --- maven-git-versioning-extension:1.1.0 ---
[INFO] Disabled.
[INFO]
[INFO] ------------------------< org.company:common-lib >------------------------
[INFO] Building common-lib 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.5.3:prepare (default-cli) @ common-lib ---
[INFO] Verifying that there are no local modifications...
[INFO]   ignoring changes on: **\pom.xml.next, **\release.properties, **\pom.xml.branch, **\pom.xml.tag, **\pom.xml.backup, **\pom.xml.releaseBackup
[INFO] Executing: cmd.exe /X /C "git rev-parse --show-toplevel"
[INFO] Working directory: C:\Repositories\common-lib
[INFO] Executing: cmd.exe /X /C "git status --porcelain ."
[INFO] Working directory: C:\Repositories\common-lib
[WARNING] Ignoring unrecognized line: ?? .mvn/maven-git-versioning-extension.xml
[WARNING] Ignoring unrecognized line: ?? pom.xml.next
[WARNING] Ignoring unrecognized line: ?? pom.xml.releaseBackup
[WARNING] Ignoring unrecognized line: ?? pom.xml.tag
[WARNING] Ignoring unrecognized line: ?? release.properties
[INFO] Checking dependencies and plugins for snapshots ...
What is the release version for "common-lib"? (org.company:common-lib) 1.0.0: :
What is SCM release tag or label for "common-lib"? (org.company:common-lib) common-lib-1.0.0: :
What is the new development version for "common-lib"? (org.company:common-lib) 1.0.1-SNAPSHOT: :

Please advise. Thank you!

Update of submodules not working

I have a related issue that the versioning extension is not adjusting the parent version of modules.

Given the following setup:
updatePom = true

A/pom.xml
with Module B defined
A/B/pom.xml with a parent entry to A including version.

When running maven on A/pom.xml then the version in A/B/pom.xlm inside the parent reference to A is not updated.

Provide commitDistance property

jgitver has a 'useCommitDistance' option. It would nice to be have a similar depth property in maven-git-versioning-extension to count the number of commits on the branch, and be able to use that in the version.

Extension replaces variables in profile activation

Hi

great extension, but is has a showstopper bug for us.
The following code is replaced by the extension from:

<profile>
      <id>kotlin</id>
      <activation>
        <file>
          <exists>${basedir}/src/main/kotlin</exists>
        </file>
      </activation>
...
</profile>

to

<profile>
  <id>kotlin</id>
  <activation>
    <file>
      <exists>C:\foo\bar\src\main\kotlin</exists>
    </file>
  </activation>
...
</profile>

which makes the generated pom useless for modules that want to inherit the profiles.

Kind regards,
Michael

Using LATEST version

I see in Maven 3 notes that LATEST and RELEASE are removed as metadata version markers. The readme of this extension still recommends usage of them. Is it different when using extension versions as compared to dependency/plugin versions?

If LATEST is no longer desirable, what is recommended for targeting this extension?

Thanks!

Incorrect artifact name in multimodule project

Hi.
For simple project the extension works as expected but for project with parent module and several child modules name of created artifact is changed only for parent build.

$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] --- maven-git-versioning-extension:3.0.2 ---
[INFO] parent:1.0-SNAPSHOT - branch: master -> version: master-1.0
[INFO] core:1.0-SNAPSHOT - branch: master -> version: master-1.0
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent
[INFO] core
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent master-1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent ---
[INFO]
[INFO] --- maven-git-versioning-extension:3.0.2:pom-replacement (pom-replacement) @ parent ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building core 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
               [... some maven build steps like cleaning, compiling and testing ... ]
[INFO]
[INFO] --- maven-git-versioning-extension:3.0.2:pom-replacement (pom-replacement) @ core ---
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ core ---
[INFO] Building jar: C:\DevTut\TestApp\parent\core\target\core-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................. SUCCESS [  0.401 s]
[INFO] core ............................................... SUCCESS [  3.245 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.113 s
[INFO] Finished at: 2018-10-18T11:52:56+02:00
[INFO] Final Memory: 20M/215M
[INFO] ------------------------------------------------------------------------

As you can see the name of core module jar is "core-1.0-SNAPSHOT" but should be "core-master-1.0".

Configuration:

<configuration>
    <branches>
        <branch>
            <pattern>.*</pattern>
            <versionFormat>${branch}-${version.release}</versionFormat>
        </branch>
    </branches>
    <tags>
        <tag>
            <pattern>.*</pattern>
            <versionFormat>release-${tag}</versionFormat>
        </tag>
    </tags>
</configuration>

Is it a bug or should I make some additional steps?

Branch Versioning Model Processor: NullPointerException

I see some changes were made relating to how to pass in git information from a CI environment, and we are now facing issues.

Our CI environment uses project.branch and project.tag arguments. Here is an example (the tag is intentionally left blank) along with the full error we are seeing:

mvn -e -Dproject.branch=my-branch-name -Dproject.tag= source:jar install

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] --- maven-git-versioning-extension:2.0.0 ---
[INFO] config-lib:0.0.0-SNAPSHOT - branch: my-branch-name -> version: my-branch-name-SNAPSHOT
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM C:\Repositories\config-lib\pom.xml: Branch Versioning Model Processor @
 @
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM C:\Repositories\config-lib\pom.xml: Branch Versioning Model Processor @

    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:383)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:397)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:388)
    at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:81)
    at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke (Method.java:508)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR]   The project  (C:\Repositories\config-lib\pom.xml) has 1 error
[ERROR]     Non-readable POM C:\Repositories\config-lib\pom.xml: Branch Versioning Model Processor: NullPointerException
java.io.IOException: Branch Versioning Model Processor
    at com.qoomon.maven.extension.gitversioning.VersioningModelProcessor.provisionModel (VersioningModelProcessor.java:158)
    at com.qoomon.maven.extension.gitversioning.VersioningModelProcessor.read (VersioningModelProcessor.java:92)
    at org.apache.maven.model.building.DefaultModelBuilder.readModel (DefaultModelBuilder.java:536)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:276)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:432)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:400)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:362)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:397)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:388)
    at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:81)
    at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke (Method.java:508)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.NullPointerException
    at java.util.Hashtable.put (Hashtable.java:505)
    at org.apache.maven.model.ModelBase.addProperty (ModelBase.java:146)
    at com.qoomon.maven.extension.gitversioning.VersioningModelProcessor.provisionModel (VersioningModelProcessor.java:127)
    at com.qoomon.maven.extension.gitversioning.VersioningModelProcessor.read (VersioningModelProcessor.java:92)
    at org.apache.maven.model.building.DefaultModelBuilder.readModel (DefaultModelBuilder.java:536)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:276)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:432)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:400)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:362)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:397)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:388)
    at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:81)
    at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke (Method.java:508)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

Our maven-git-versioning-extension.xml file looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<!-- https://github.com/qoomon/maven-git-versioning-extension -->
<configuration>
	<branches>
		<branch>
			<pattern>.*</pattern>
			<versionFormat>${branch}-SNAPSHOT</versionFormat>
		</branch>
	</branches>
	<tags>
		<tag>
			<pattern>v[0-9].*</pattern>
			<prefix>v</prefix>
			<versionFormat>${tag}</versionFormat>
		</tag>
	</tags>
</configuration>

Looking at the changes linked above, I'm not sure if project.branch and project.tag were removed in favor of gitVersioning.commitRefName, but when I try and build using argument instead I am getting the same error:

mvn -e -DgitVersioning.commitRefName=my-branch-name source:jar install

Our builds are failing because we were referencing the LATEST version for this extension. If I set it to v1.2.0 it succeeds.

Disable warning is spamming console

I need to disable the versioning for some maven goals, this results in lots of warnings:

$ mvn -B release:prepare -DdryRun=true -Dversioning.disable=true -DautoVersionSubmodules=true
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------- maven-git-versioning-extension:4.10.1 ----------------
[INFO] Adjusting project models...
[INFO]
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[INFO] Reactor Build Order:
[INFO]
[INFO] FOO Parent pom                                              [pom]
[INFO] FOO rules                                                   [jar]
[INFO] FOO unit test depchain                                      [pom]
[INFO] FOO integration test depchain                               [pom]
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled
[WARNING] skip - versioning is disabled

As the disabling is intended, it should be a single INFO message, not hundreds of warnings.

Incorrect version in a multimodule project with enforce plugin

I have a problem with maven-git-versioning-extension. Enforcer plugin fails the build during checking a version compatibility.

Example of a project:
https://github.com/OneHalf3544/mgvp-bug-example/tree/feature/TICKET-123/description

pom.virtual.xml files contain a correct version, but Enforcer plugin shows the error:

Dependency convergence error for mgve-example:printer:1.0.0-TICKET-123-description-TICKET-123-description-SNAPSHOT paths to dependency are:
+-mgve-example:world-greater:1.0.0-TICKET-123-description-SNAPSHOT
  +-mgve-example:greater:1.0.0-TICKET-123-description-SNAPSHOT
    +-mgve-example:printer:1.0.0-TICKET-123-description-TICKET-123-description-SNAPSHOT
and
+-mgve-example:world-greater:1.0.0-TICKET-123-description-SNAPSHOT
  +-mgve-example:printer:1.0.0-TICKET-123-description-SNAPSHOT

Empty properties are overwritten

We see a regression with version 4.4.1

Following structure:
PARENT (property: <sonar.tests>src/test</sonar.tests>)

  • Module1 (property: <sonar.tests></sonar.tests>)

When running with versioning extension the property in Module1 is updated to the value of the parent.

Kind regards,
Michael

NPE in empty project

Reproduce:

  • create new git project
  • add src files and the pom.xml (but don't add them with git add & git commit)
  • run "mvn clean install"
  • the following error occures
mvn clean install 
[INFO] Scanning for projects...
[INFO] --- maven-branch-versioning-extension:2.6.0 ---
[ERROR] Internal error: java.lang.NullPointerException -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.NullPointerException
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:121)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.NullPointerException
	at com.qoomon.maven.extension.branchversioning.BranchVersioningModelProcessor.deduceBranchVersion(BranchVersioningModelProcessor.java:190)
	at com.qoomon.maven.extension.branchversioning.BranchVersioningModelProcessor.provisionModel(BranchVersioningModelProcessor.java:124)
	at com.qoomon.maven.extension.branchversioning.BranchVersioningModelProcessor.read(BranchVersioningModelProcessor.java:72)
	at org.apache.maven.model.building.DefaultModelBuilder.readModel(DefaultModelBuilder.java:533)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:273)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:469)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:438)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:401)
	at org.apache.maven.graph.DefaultGraphBuilder.collectProjects(DefaultGraphBuilder.java:419)
	at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor(DefaultGraphBuilder.java:410)
	at org.apache.maven.graph.DefaultGraphBuilder.build(DefaultGraphBuilder.java:83)
	at org.apache.maven.DefaultMaven.buildGraph(DefaultMaven.java:491)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:219)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	... 11 more
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorException

if you have added at least one file with git it works

Update of versions for dependencies

I have a last issue that could be improved by this great extension.
Please see this demo project:
https://github.com/reitzmichnicht/versioning-demo

It is using the version of modules inside its own dependency section.
The maven-versions-plugin or the maven-release-plugin also change them if the version used there is identical to the old version. Without a fix the build breaks if the old versions are not already installed to the repo :(

Perhaps you can have a look at their code
https://github.com/mojohaus/versions-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java

Releasedate

Hey,

I am currently waiting for a new release to use the commit specific configurations. Will there be a release soon?

Question: update changelog

We are currently using this plugin and it's working great. We are on a specific version (1.2.0) and I'm doing some work in our project structure and wondering about upgrading to the latest as it would be an ideal time. However I'm not sure of reason/rationale for us to do so and if it would be necessary or desirable.

I do see the breaking changes in README, but I'm curious if there were other features or enhancements that have been added that would prompt us to get on the latest?

Any advice would be appreciated.

Updating dependencies versions

I plan to use this extension to manage the versions of our feature branches, but I have a case which does not seem to be covered by the extension.
Our project is composed of several git repositories, with dependencies between each others. So we have a project A in its own repository which depends on a project B also in its own repository. In the pom of the project A, I have the following dependency:

<version>1.0.0-SNAPSHOT</version>
...
<properties>
  <project.b.version>2.0.0-SNAPSHOT</project.b.version>
</properties>
...
<dependencies>
  <dependency>
      <groupId>my.group</groupId>
      <artifactId>project.b</artifactId>
      <version>${project.b.version}</version>
    </dependency>
</dependencies>

We need to work in parallel in both projects (some changes in project A requires some changes in project B).
The extension allows to replace the version of the module but I did not find a way to do it for dependencies/properties. Is there a way to do it ?
If not, could it be an interesting improvement, or is it beyond the scope of this extension ?

Environment variable VERSIONING_GIT_BRANCH not working

Bug: me.qoomon.maven.gitversioning.GitVersioningModelProcessor.getOption(String). The following line of code result to:
Actual:
VERSIONING_GIT.BRANCH
Expected:
VERSIONING_GIT_BRANCH

value = System.getenv("VERSIONING_" + name.replaceAll("[A-Z]", "_$0").toUpperCase());

See

System.out.println("VERSIONING_" +"git.branch".replaceAll("[A-Z]", "_$0").toUpperCase());

at https://repl.it/languages/java.

Wrong build version shown in output

The replacement of slashes in branch names works fine for the build version, nevertheless the wrong version is displayed.

[INFO] Scanning for projects...
[INFO] --- maven-branch-versioning-extension:2.6.0 ---
[INFO] project-name:0.1.0-SNAPSHOT - branch: feature/COM-28-initial-setup - version: feature/COM-28-initial-setup-SNAPSHOT
[INFO] 

Actual build version is named correctly

project-name-feature-COM-28-initial-setup-SNAPSHOT-sources.jar

are multi-module projects supported

Extension works for me for simple project, but multi-module projects prints correct substitution at start of build (yet root module is listed 5 times for 2 module 1 common root project), but later no version substitutions are made... Do I have somewhere error or is this expected behavior/

Wrong regex anchor in removePrefix

Hi, your library works great for me but I've hit one problem recently.
I need to use the <prefix> in branch configuration but it does not affect the final version.
I have tracked the problem down to StringUtil#removePrefix - there is wrong regex anchor which makes the match never pass and prefix is never removed. I already have a patch which fixes the issue for me locally:

     public static String removePrefix(String string, String prefix) {
 
         String prefixRegex = prefix;
-        if(!prefix.startsWith("$")){
-            prefixRegex = "$" + Pattern.quote(prefix);
+        if(!prefix.startsWith("^")){
+            prefixRegex = "^" + Pattern.quote(prefix);
         }
 
         return string.replaceFirst(prefixRegex, "");

And a test (which fails on current master) showing this indeed works:

+package me.qoomon.maven.extension.gitversioning;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+public class StringUtilTest {
+
+    @Test
+    public void removesPrefixRemovesPatternFromStartOfWord() throws Exception{
+        assertEquals("RestOfText", StringUtil.removePrefix("somePrefixRestOfText", "somePrefix"));
+    }
+
+    @Test
+    public void removePrefixLeavesPatternInsideWord() throws Exception{
+        assertEquals("someTextWithPatternInMiddle", StringUtil.removePrefix("someTextWithPatternInMiddle", "Pattern"));
+        assertEquals("someTextEndingWithPattern", StringUtil.removePrefix("someTextEndingWithPattern", "Pattern"));
+    }
+}

I'd be more than happy to submit a PR but have found no contributing section, what is your policy?
It would be great if this fix could get added and appear in maven central.

Cheers

Cannot set custom versionFormat for specific branch

Hello, I am trying to have a custom branch (alongside master) without the branch name. But whenever I build the Jenkins job, the branch name is displayed for all branches. This is how the config xml looks like:

<configuration>
    <branches>
        <branch>
            <pattern>develop</pattern>
            <versionFormat>${version.release}</versionFormat>
        </branch>
		<branch>
            <pattern>master</pattern>
            <versionFormat>${version.release}</versionFormat>
        </branch>
		<branch>
            <pattern>custom_branch</pattern>
            <versionFormat>${version.release}</versionFormat>
        </branch>
        <branch>
             <pattern>release/.*</pattern>
             <prefix>release/</prefix>
             <versionFormat>${branch}${version.release}-SNAPSHOT</versionFormat>
         </branch>
    </branches>
</configuration>

Common config directory for multiple projects

Hi,
I have a sort-of "multi-project" configuration with an aggregate pom.xml that defines 5 modules, e.g.

...
<groupId>my.group</groupId>
<artifactId>aggregate<artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
  <module>m1</module>
  <module>m2</module>
  ...
  <module>m5</module>
</modules>

However the m1-m5 projects do not have the aggregate pom as parent, because they inherit the plugins behaviour and properties from an organizational-level parent pom (which means that the solution of issue #6 does not apply in this case).
So, to make the maven-git-versioning-extension plugin to work without copying the extensions.xml and maven-git-versioning-extension.xml to all the projects I would need an additional optional parameter for the plugin to override the ${project.basedir}/.mvn directory with a common path.
I would be glad to give it a try and create a pull request if you think that this is a valid requirement.

Support persisted version in original pom

The plugin is really working great for feature branches, but there is one feature missing that would be useful for release branches.

Having a release branch the plugin could automatically determine the version from the branch name, but we also want to commit the sources with this version.
So would be great to have a optional setting in maven-git-versioning-extension.xml that the versioning is not done in a temporary file like for feature branches but in the original pom.

Kind regards,
Michael

Usage with ear projects

We are using this plugin (v1.2.0) for our jar and war builds and are quite happy with it. We are wanting to do the same for our ear applications but are not sure how it would work and was wondering if there was any advice you can give.

The simple case we are looking at is a project that needs to be generated and output as an ear, but all it has is a single web project in it (war). We're not sure on the best way to structure the war/ear projects, but we are thinking we will have two Maven projects. The war project will look as normal for our web application, and the ear will reference that same war for its bundling.

We're not sure if we'd need to run multiple build steps: one for war and one for ear?

Any advice you could give would be great. Thank you!

broken build with 4.0.0

Hello,

the 4.0.0 that's been released last night breaks our builds with the following error :

Non-readable POM redacted/pom.xml: Git Versioning Model Processor: Element 'branches' does not have a match in class me.qoomon.maven.gitversioning.GitVersioningExtensionConfiguration at line 2

Are there known breaking changes that we should be aware of ? Release notes ?

Our configuration:

<configuration>
    <branches>
        <branch>
            <!-- it appears that the standard config (using prefix) does not work
                 -> reimplement it using regex capture                             -->
            <pattern><![CDATA[release/(?<release>.*)]]></pattern>
            <versionFormat>${release}-SNAPSHOT</versionFormat>
        </branch>
    </branches>
    <tags>
        <tag>
            <!-- same as above -->
            <pattern><![CDATA[v(?<foo>.*)]]></pattern>
            <versionFormat>${foo}</versionFormat>
        </tag>
    </tags>
    <commit>
        <versionFormat>${commit}</versionFormat>
    </commit>
</configuration>

Version 5.0.0 not working with maven 3.6.2

Hi, after updating version from 4.10.2 to 5.0.1 I found out that artifacts are not build locally, we're using CircleCI as well and there everything seems to be OK. I am running OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10) and Apache Maven 3.6.2

What about a dirty indicator?

It would be very useful to know if the build was done with a clean or dirty repo, I can't find any info in the documentation about this.

Does not work with maven 3.6.2

Although it works consistently with maven 3.6.1, including the output of lots of warnings when -Dversioning.disable=true is given, it seems that with maven 3.6.2 there is no version processing at all, i.e.

  • mvn --non-recursive exec:exec -Dversioning.disable=true -Dexec.executable='echo' -Dexec.args='${project.version}' does not give warnings
  • mvn --non-recursive exec:exec -Dexec.executable='echo' -Dexec.args='${project.version}' -q does not give a processed version

References:

Using with non-multi-module parent pom

We are (happily) using your extension but are currently on a very old version (1.2.0). We are upgrading to a newer version but it seems like usage with parent pom has changed slightly.

We have a "parent" pom that is the parent of all the projects in our organization. It has some common settings for distributionManagement and build plugins. It is not related to any specific project and doesn't have any modules.

In our individual applications we:

  • reference the parent pom
  • use this extension to set version based on branch or tag name (branch name in development, tag name for releases)

However when updating to version 4.8.0 of this extension I see that parent pom version logic is also present and getting modified by this extension and I am not sure how to handle it.

I have an example repo here: https://github.com/l3ender/maven-demo. Note that I have the parent pom in the same repo for convenience, but in our environment we publish it to our internal repository separately. Running mvn clean results in the following, where both current project and parent project version is updated.

-> mvn clean -Dgit.branch=abc
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------- maven-git-versioning-extension:4.8.0 -----------------
[INFO] Adjusting project models...
[INFO]
[INFO] --- l3ender:maven-demo @ branch abc ---
[INFO] properties:
[INFO]
[INFO] --- l3ender:maven-demo-parent @ branch abc ---
[INFO] project version: abc-SNAPSHOT
[INFO] properties:
[INFO]
[INFO]
[INFO] -------------------------< l3ender:maven-demo >-------------------------
[INFO] Building maven-demo abc-SNAPSHOT

In our scenario we don't want the parent pom version to be modified as it isn't part of this project. Can you please advise on a way to accomplish this or to think about it differently?

Change the default location of .git-versioned.pom.xml to a folder inside target-folder

The .git-versioned.pom.xml is always generated when maven build is executed. Therefore it should not be stored in git. In your current plugin-configuration the default folder of .git-versioned.pom.xml is currentProject.getBasedir(). I think, it is common for a maven-project, that generated files are stored inside the target-folder.

  • the maven-clean-plugin doesn't need extra configuration to delete the file.
  • the target-folder is usually ignored via .gitignore

Jenkins multi-branch-pipeline is giving commit versions instead of branch versions

Steps to reproduce:
Create project with a Jenkinsfile
Create a multi branch pipeline in Jenkins.
Create a branch called: feature/test-branch
Use the following config:

<configuration>
    <branches>
        <branch>
            <pattern>master</pattern>
            <versionFormat>${version.release}</versionFormat>
        </branch>
        <branch>
            <pattern>feature/.*</pattern>
            <prefix>feature/</prefix>
            <versionFormat>${branch}-SNAPSHOT</versionFormat>
        </branch>
    </branches>
    <tags>
        <tag>
            <pattern>version/.*</pattern>
            <prefix>version/</prefix>
            <versionFormat>${tag}</versionFormat>
        </tag>
    </tags>
</configuration>

Expected result:
See test-branch-SNAPSHOT as the version.

Actual results
[INFO] --- maven-git-versioning-extension:3.0.2 ---
[INFO] backend:1.0.2-SNAPSHOT - commit: bc4edda51ebe991aeb7a210e7ec606973d02c8c9 -> version: bc4edda51ebe991aeb7a210e7ec606973d02c8c9

Failure on multi-project with aggregation and external parent on modules

Fixing #37 broke the feature introduced with #34 in a specific use-case that had no tests for.
In particular, it seems that the changes introduced in me.qoomon.maven.gitversioning.ModelProcessor#getParentPom do not take into account the case where one module exists having an external POM as a parent (e.g. a spring boot starter), and a version mismatch exception is thrown, making the build to fail.

Property variables are replaced

This is a regression from 4.4.0 to 4.4.3
Having the following properties in my pom.xml:

<properties>
    <skipTests>false</skipTests>
    <skipUTs>${skipTests}</skipUTs>
    <skipITs>${skipTests}</skipITs>
    <scm-commit>${git.commit}</scm-commit>
    <scm-branch>${git.branch}</scm-branch>
</properties>

This is now resolved by this extension to:

    <skipTests>false</skipTests>
    <skipUTs>true</skipUTs>
    <skipITs>true</skipITs>
    <scm-commit>0d434d66a1e2f9aa10d78f9ab8198ce4a789ea02</scm-commit>
    <scm-branch>master</scm-branch>

Kind regards,
Michael

Prefix isn't removed since 3.1.1

Since version 3.1.1 the prefix isn't removed from the version tag...

Using this config:

<configuration>
  <branches/>
  <tags>
    <tag>
      <pattern>v.*</pattern>
      <prefix>v</prefix>
      <versionFormat>${tag}</versionFormat>
    </tag>
  </tags>
</configuration>

I expect when building a git tag "v1.6.2" a version 1.6.2 to be build, but it is v1.6.2

Wrong version with multi-module project and no parent POM

Maven does not enforce module POMs to have the main "packaging" POM as a parent, whereas me.qoomon.maven.gitversioning.ModelProcessor#findMvnDir assumes so.
This causes the configuration not to be found and the versioning scheme to fallback to the default "commit" when a single module is built from its module directory.
I am opening a pull request with a failing test and a potential fix.

differences with jgitver?

How is this different from jgitver? You and @McFoggy both seem to have the same goals/ideas. But 2 different implementations have arised. Both actively worked on. Which one should I choose?

broken 'restrict project versioning to root- and sub-projects'

Having issue with detecting version of multimodule project after 4.10.0 release.

Sample project attached broken.zip
On root level version (feature-1) detects ok

broken% mvn --non-recursive exec:exec -Dexec.executable='echo' -Dexec.args='${project.version}' -q
feature-1

On bundle level version (Feature-1) does not detects. Fallback version "currentVersion" is found

broken% cd bundle
broken/bundle% mvn --non-recursive exec:exec -Dexec.executable='echo' -Dexec.args='${project.version}' -q
currentVersion

maven-git-versioning-extension.xml is ignored when building a submodule in a multi-module project

Hello,
1st let me say thank you for making this great plug-in. It solves the issues with maven versioning and CI when using gitflow (or git oneflow in our case) with feature branches.

I discovered the following behaviour that I'd consider a bug.

Setup:

  • a multi-module project
  • at the top level project, extensions.xml and maven-git-versioning-extension.xml are located
  • each module has the top level project as it's parent

Test:

  • when running maven at top level (e.g. mvn clean), everything works as expected.
  • when running maven at top level restricted to a module (e.g. mvn clean --projects module1), everything works as expected.
  • when running machen at a module level (e.g. cd module1; mvn clean), the extension is inherited from the top level module but the config is ignored. In my case, the module is built with the git tag as version, not with the branch name.
  • It can be work-arounded by copying maven-git-versioning-extension.xml to every submoule (e.g. to module1/.mvn/maven-git-versioning-extension.xml)

ClassCastException thrown when using maven-antrun-plugin in a build

We are using the latest version of your plugin (v4.1.0) and are seeing a raised exception in the build lifecycle when using it alonside another plugin "maven-antrun-plugin"

Caused by: java.lang.ClassCastException: java.util.Properties cannot be cast to java.lang.String
at org.apache.maven.plugin.antrun.AntRunMojo.copyProperties (AntRunMojo.java:406)

It fails to iterate over every Properties key/values.

I've look into your code an i'm seeing a setProperties that breaks the Javadoc on Properties.
(taken from Oracle Javadoc)

The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

If you look closely in the class ModelProcessor at line 266, you are passing configs to the plugin using
model.getProperties().put(...)

Here is the offending code:

// pass config to plugin
Properties pluginConfig = new Properties();
pluginConfig.setProperty("updatePom", Boolean.toString(updatePomOption));
model.getProperties().put(VersioningMojo.class.getName(), pluginConfig);

Could you pass your configs in keys/values that are actual Strings ?

Otherwise great work! really helpful!

Possibility to disable extension for a specific branch

We`re having problem using this specific configuration in the master branch:

<branch>
    <pattern>master</pattern>
    <versionFormat>${version}</versionFormat>
 <property>
       <pattern>revision</pattern>
       <value>
           <pattern>.*</pattern>
            <format>${version}</format>
       </value>
     </property>         
 </branch>

We are using maven modules and we use dynamic variable in the module POM.xml, so we're using the flatten maven plugin. Long story story short, it seems to cause a conflict with the maven extension because maven is always complaining that it cannot find the ${revision} parent package

...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.company..common:commons-core:[unknown-version]: Failure to find com.company.common:common:pom:${revision} in ....

Maybe because the flatten plugin is merging the pom.xml AFTER the verison extension runs.

Anyway, I won't ask for help debugging this, but basically, what I would need, is to tell the extension to do... abolutely NOTHING in the branch master. I simply want to hard-code everything in the pom.xml once in the master branch. I've tried to remove the entry for master, I've also tried to use an empty configuration node. With either configuration, the extensions falls into a default mode of using the commit hash as the version. Is there any way to tell the extension to do NOTHING ? Don't touch the version number, don't touch the variable, I'll handle them.

For now, I'm removing the extension once in the master branch, but that's not ideal.

thanks

Null pointer in multi-module

We are having a null pointer when generating a multi module project. The problem is cause because we dont have the version tag in the child project.

my child POM

       <parent>
               <groupId>com.myComp.document</groupId>
               <artifactId>document-business-processes</artifactId>
               <version>0.0.0.5-SNAPSHOT</version><relativePath>..</relativePath>
       </parent>
       <artifactId>document-business-processes-contract</artifactId>
       <name>Document Business Processes Contract</name>
       
       .....

The stack trace

Non-readable POM C:\Data\eclipse-2018\document-business-processes\document-business-processes-contract\pom.xml: Git Versioning Model Processor: NullPointerException
java.io.IOException: Git Versioning Model Processor
    at me.qoomon.maven.gitversioning.GitVersioningModelProcessor.processModel (GitVersioningModelProcessor.java:194)
    at me.qoomon.maven.gitversioning.GitVersioningModelProcessor.read (GitVersioningModelProcessor.java:73)
    at org.apache.maven.model.building.DefaultModelBuilder.readModel (DefaultModelBuilder.java:536)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:276)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:432)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:400)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:363)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:414)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:405)
    at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:82)
    at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.NullPointerException
    at me.qoomon.gitversioning.GitVersioning.determineVersion (GitVersioning.java:70)
    at me.qoomon.maven.gitversioning.GitVersioningModelProcessor.processModel (GitVersioningModelProcessor.java:135)
    at me.qoomon.maven.gitversioning.GitVersioningModelProcessor.read (GitVersioningModelProcessor.java:73)
    at org.apache.maven.model.building.DefaultModelBuilder.readModel (DefaultModelBuilder.java:536)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:276)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:432)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:400)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:363)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:414)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:405)
    at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:82)
    at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

Branch is added to version

Trying to have the both version and branch as part of the snapshot name.

Current config snippet:

<branch> <pattern>.*</pattern> <versionFormat>${version.release}-${branch}-SNAPSHOT</versionFormat> </branch> </branches>

Seems the branch is added to ${version.release}, as we get quite a long snapshot name after a few runs.
From pom version 1.0.7-SNAPSHOT after first run on branch "branch-deploy", the name is: 1.0.7-branch-deploy-branch-deploy-SNAPSHOT.

This keeps adding up:
1.0.5-branch-deploy-branch-deploy-branch-deploy-branch-deploy-SNAPSHOT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.