Sunil Kumar
Sunil Kumar

Reputation: 5647

How to build maven project both Snapshot and Release build simultaneously

I have a requirement to build both Snapshot versions and Release build at a time.

To build snapshot versions I did like this

<groupId>com.abc.xyz</groupId>
<artifactId>service</artifactId>
<version>1.0.3-SNAPSHOT</version>

<distributionManagement>
    <snapshotRepository>
        <id>mvn-git-repo</id>
        <uniqueVersion>true</uniqueVersion>
        <name>maven git repository</name>
        <url>file:/home/mvn-github-repo/snapshot</url>
    </snapshotRepository>
</distributionManagement>

To build release versions,

<groupId>com.abc.xyz</groupId>
<artifactId>service</artifactId>
<version>1.0.3</version>

<distributionManagement>
    <repository>
        <id>mvn-git-repo</id>
        <uniqueVersion>true</uniqueVersion>
        <name>maven git repository</name>
        <url>file:/home/mvn-github-repo/release</url>
    </repository>
</distributionManagement>

Is it possible to make both together, so that it should generate snapshot version and as well release version jars at a time and deploy in respective repositories.If possible what is the version I should keep in pom ?

Upvotes: 1

Views: 2588

Answers (1)

ravthiru
ravthiru

Reputation: 9623

You use profile to define the version and repo, like this

<version>${buildVersion}</version>
.
.
.
<profiles>
    <profile>
        <id>snapshot-repo</id>
        <activation>
            <property>
                <name>snapshot</name>
                <value>true</value>
            </property>
        </activation>
        <properties>
         <buildVersion>1.0.3-SNAPSHOT</buildVersion>
        </properties>
        <distributionManagement>
            <repository>
            </repository>
            <snapshotRepository>
            </snapshotRepository>
        </distributionManagement>
    </profile>

    <profile>
        <id>git-repo</id>
        <activation>
            <property>
                <name>!snapshot</name>
            </property>
        </activation>
        <properties>
          <buildVersion>1.0.3</buildVersion>
        </properties>
        <distributionManagement>
            <repository>

            </repository>
            <snapshotRepository>

            </snapshotRepository>
        </distributionManagement>
    </profile>

Then build by with -Dsnapshot=true

Upvotes: 1

Related Questions