Reputation: 1428
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):
mvn deploy -P P1
" everything goes fine (war and pom are deployed to Nexus)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.
Upvotes: 2
Views: 5058
Reputation: 1428
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>
Upvotes: 1
Reputation: 97467
Simple answer. It's not possible. The problem is based on the usage of profiles which are evil in this relationship.
The solution for such things is to create a Maven build which is able to produce two war files which are the results for this build.
I assume you have different properties for different environments like the following:
.
|-- pom.xml
`-- src
|-- main
| |-- java
| |-- resources
| |-- environment
| | |-- test
| | | `-- database.properties
| | |-- qa
| | | `-- database.properties
| | `-- production
| | `-- database.properties
| `-- webapp
which means you need to create in your case two war file which only differ in the content of the property files. In the above having three environments.
What you need is an assembly descriptor for each of your environments like:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>test</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<useProjectArtifact>true</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>WEB-INF</outputDirectory>
<directory>${basedir}/src/main/environment/test/</directory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
And the appropriate execution of in this case the maven-assembly-plugin like the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/test.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>qa</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/qa.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>production</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/production.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
This will result in a single run of maven via:
mvn package
which produces three different war files which contain different property file or files with different content. This is the solution without profiles which works perfectly and will deploy the three different war file which will be named like:
and that's the result you need to solve your problem.
Upvotes: 9