bdemers / maven-external-version

Apache License 2.0
28 stars 20 forks source link

Maven External Version

[!NOTE] This usecase is now part of Maven 4. Please try Maven 4 and provide feedback to the Maven team!

The Current State of Apache Maven 4 - Karl Heinz Marbaise

Archived Content

Requires Maven 3.2.0 or later.

(github is the temporary home.)

What is this?

The main use-case of this extension plugin is to allow the POM versions to be updated during a build and NOT require the pom.xml file to be modified (causing potential merge conflicts down the road, or untracked changes)

When would I use this?

Say, you have github-flow approach to branching, that is you create a lot of small feature branches, they get merged into 'master' then you release off of master. Currently if you want to build multiple SNAPSHOT branches in CI and and deploy them to a Maven repository, you need to update your POMs before you deploy. This will help you with that.

For example if your master is at version 1.1.42-SNAPSHOT, and for your feature branches you want to add your branch/feature name to the version, e.g. for branch everything, you want to end up with 1.1.42-everything-SNAPSHOT

Need to add real example here, when I'm more awake. Until then, look at this.

Quick and Dirty Example

In your pom add:


    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-external-version-plugin</artifactId>
        <version>0.1.0-SNAPSHOT</version>
        <extensions>true</extensions>
        <configuration>
            <strategy hint="sysprop"/>
        </configuration>
    </plugin>

To replaced the whole version you can run:

mvn install -Dexternal.version=1.1.42

To add just a qualifier to the version:

mvn install -Dexternal.version-qualifier=rc1
# if the original version was 1.1.1 the new version would be 1.1.1-rc1

Add a version qualifier to all non-master branches

mvn install -Dexternal.version-qualifier=$(git symbolic-ref --short HEAD| sed s_^master\$__)

Or how about a short git hash?

mvn install -Dexternal.version-qualifier=$(git rev-parse --short HEAD)

Configuration & parameters


    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-external-version-plugin</artifactId>
        <version>X.Y.Z</version>
        <extensions>true</extensions>
        <configuration>
            <strategy hint="STRATEGY"/>
            <generateTemporaryFile>true/false</generateTemporaryFile>
            <deleteTemporaryFile>true/false</deleteTemporaryFile>
        </configuration>
    </plugin>

Strategy : file

This strategy reads the first line of a given file to extract the version to use.

Usage


    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-external-version-plugin</artifactId>
        <version>X.Y.Z</version>
        <extensions>true</extensions>
        <configuration>
            <strategy hint="file">
                <versionFilePath>SOME_FILE</versionFilePath>
            </strategy>
        </configuration>
    </plugin>

Parameters

Strategy : script

This strategy allows to execute a given command ; the first line of stdout output will be used as version.

Usage


    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-external-version-plugin</artifactId>
        <version>X.Y.Z</version>
        <extensions>true</extensions>
        <configuration>
            <strategy hint="script">
                <script>SOME_COMMAND</script>
            </strategy>
        </configuration>
    </plugin>

Parameters

Strategy : sysprop

This strategy uses 2 system properties to define the new project version:

Usage


    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-external-version-plugin</artifactId>
        <version>X.Y.Z</version>
        <extensions>true</extensions>
        <configuration>
            <strategy hint="sysprop" />
        </configuration>
    </plugin>

TODO:

Other Thoughts

An extension isn't exactly the most flexible way of adding this feature to Maven, but it seems to work (at least with simple cases)