Skip to content
Advertisement

How to set different version based on profile maven

I have a java project with mvn I need to have different version based on the mvn profile

<GroupId>com.company.com</GroupId>
<ArtifactId>xxx<ArtifactId/>
<Version>{version.profile}</version>

How do I set version.profile based on the profile ?

Advertisement

Answer

you can create profiles like below

<profiles>
    <profile>
        <id>demo1</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <demolib.version>1.0.0</demolib.version>
        </properties>
    </profile>
    <profile>
        <id>demo2</id>
        <properties>
            <demolib.version>2.0.0</demolib.version>
        </properties>
    </profile>
</profiles>

then your default profile is demo1, and version is 1.0.0 you can use variables in profile in your maven

<GroupId>com.company.com</GroupId>
<ArtifactId>xxx<ArtifactId/>
<Version>{demolib.version}</version>

if you want to build with version 2.0.0 just run maven with mvn -Pdemo2 package also you can use multiple parameter like mvn -Pdemo2,example2 package

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement