Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 800
Andrés Oviedo Avatar asked Dec 02 '25 06:12

Andrés Oviedo


1 Answers

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:

  1. artifactId-version-test.war
  2. artifactId-version-qa.war
  3. artifactId-version-production.war

and that's the result you need to solve your problem.

like image 127
khmarbaise Avatar answered Dec 05 '25 00:12

khmarbaise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!