Search code examples
mavenmaven-2maven-3nexus

How to maven release multiple profiles project when redeploys are disabled


Question: How should I release a maven project which has 2 exclusive profiles when redeploys are disabled on Nexus?

Example (edited): I have a maven project MyArtifact with 2 profiles in pom.xml (P1 and P2) which generates 2 different ears. Each profile configures the maven-ear-plugin to include different modules and auto-generate the application.xml. The generated artifacts are MyArtifact-1.0-P1.ear (2 war modules) and MyArtifact-1.0-P2.ear (3 war modules).

Problem 1 (redeploy to nexus):

  1. When I execute "mvn deploy -P P1" everything goes fine (war and pom are deployed to Nexus)
  2. When I execute "mvn deploy -P P2" error! Nexus complains about redeploying the pom.xml.

Problem 2 (maven-release-plugin):

When using the maven-release-plugin to release for the multiple profiles, maven do a lot of things (checkout and tag CSM, updates pom versions, turns to tag, commit to CSM, etc...). At least it's not efficient nor practical to have to re-release/re-tag for each profile execution.


Solution

  • Yeah!

    Insted of using profiles, I'am using the maven <executions> feature: 1 execution for each profile i have. Each execution has to generates resources in a different working folder. Each artifact has different classifier. When deploying maven will find the 3 artifacts (pom, ear, ear) and will deploy them to Nexus fine.

    Below is the example. Please let me know it you have any problems with it:

    <plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <executions>
                <execution>
                    <!-- Disable default execution -->
                    <id>default-ear</id>
                    <phase>none</phase>
                </execution>
                <execution>
                    <!-- Disable default execution -->
                    <id>default-generate-application-xml</id>
                    <phase>none</phase>
                </execution>
                <execution>
                    <!-- execution for profile P1 -->
                    <id>P1</id>
                    <goals>
                        <goal>ear</goal>
                        <goal>generate-application-xml</goal>
                    </goals>
                    <configuration>
                        <!-- Different working directory for each profile (very important) -->
                        <workDirectory>target/P1</workDirectory>
                        <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                        <generateApplicationXml>true</generateApplicationXml>
                        <displayName>MyArtifactLibraryP1</displayName>
                        <!-- Different classifier for each profile (very important) -->
                        <classifier>P1</classifier>
                        <modules>
                            <jarModule>
                                <groupId>com.example</groupId>
                                <artifactId>MyWar1</artifactId>
                                <includeInApplicationXml>true</includeInApplicationXml>
                            </jarModule>
                            <jarModule>
                                <groupId>com.example</groupId>
                                <artifactId>MyWar2</artifactId>
                                <includeInApplicationXml>true</includeInApplicationXml>
                            </jarModule>
                        </modules>
                    </configuration>
                </execution>
                <execution>
                    <id>P2</id>
                    <goals>
                        <goal>ear</goal>
                        <goal>generate-application-xml</goal>
                    </goals>
                    <configuration>
                        <workDirectory>target/P2</workDirectory>
                        <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                        <generateApplicationXml>true</generateApplicationXml>
                        <displayName>MyArtifactLibraryP2</displayName>
                        <classifier>P2</classifier>
                        <modules>
                            <jarModule>
                                <groupId>com.example</groupId>
                                <artifactId>MyWar1</artifactId>
                                <includeInApplicationXml>true</includeInApplicationXml>
                            </jarModule>
                            <jarModule>
                                <groupId>com.example</groupId>
                                <artifactId>MyWar2</artifactId>
                                <includeInApplicationXml>true</includeInApplicationXml>
                            </jarModule>
                            <jarModule>
                                <groupId>com.example</groupId>
                                <artifactId>MyWar3</artifactId>
                                <includeInApplicationXml>true</includeInApplicationXml>
                            </jarModule>
                        </modules>
                    </configuration>
                </execution>
            </executions>
        </plugin>