Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maven profile for artifact versioning

I want a project's version number to be as the follow format for the normal release versioning:

<version>1.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
......

On the other hand, I want to have a built artifact for every change merged like below:

<version>1.0-SNAPSHOT-${timestamp}</version>

Can I achieve this by using maven profile? something like:

<profiles>
    <profile>
        <id>normal</id>
        <version>1.0-SNAPSHOT<version>
    </proifle>
    <profile>
        <id>build</id>
        <version>1.0-SNAPSHOT-${timestamp}<version>
    </proifle>
</profiles>

so that I can build it like :

mvn package -P normal  // this gives me artifact-1.0-SNAPSHOT.jar
or
mvn package -P build     // this gives me artifact-1.0-SNAPSHOT-${timestamp}.jar 

if profile can solve this problem, what are the other approaches?

like image 895
Shengjie Avatar asked Dec 20 '22 22:12

Shengjie


2 Answers

Though I wouldn't recommend this approach, you can use profiles for this task. Here's how it can be done:

<version>${projectVersion}</version>
...
<profiles>
    <profile>
        <id>normal</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <projectVersion>1.0-SNAPSHOT</projectVersion>
        </properties>
    </profile>
    <profile>
        <id>build</id>
        <properties>
            <projectVersion>1.0-SNAPSHOT-${timestamp}</projectVersion>
        </properties>
    </profile>
</profiles>
like image 160
Andrew Logvinov Avatar answered Dec 26 '22 12:12

Andrew Logvinov


Use the Builder Number Plugin and/or evaluate the built-in timestamp property. Anyway, your approach is not recommended because a SNAPSHOT has always to be up to date.

like image 42
Michael-O Avatar answered Dec 26 '22 10:12

Michael-O