Using the maven profile to control artifact versions

I want the project version number to be like the following format for the normal version release:

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

On the other hand, I want to have a built-in artifact for each merge, as shown below:

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

Can I achieve this using the maven profile? sort of:

<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 this:

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 a profile can solve this problem, what are the other approaches?

+3
source share
2 answers

Although I would not recommend this approach, you can use profiles for this task. Here's how to do it:

<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>
+5
source

Builder Number Plugin / . , , SNAPSHOT .

+2

All Articles