Why can't I activate Maven2 profile from another profile?

I have a multi-module Maven2 project that creates a web application. The application is connected to the server and database. Several server instances are deployed in our environment, and there are also several backends and database instances for development, UAT, production, etc. Thus, each application configuration needs these three coordinates:

  • front-end server
  • server
  • Db

I am working on unifying and automating application configuration. It is easy and obvious to present these various configurations as profiles in Maven. Then I can create a specific configuration by activating one profile from each group, for example.

mvn -Pserver.Server1,backend.prod,db.uat clean install 

This is a bit tedious for type and error pricing - if a particular server is improperly configured to connect to the wrong database, the price can be high. One obvious way to fix this would be to include all the useful combinations of profiles in script files.

But I thought that I could be smarter than activating the necessary back-end and DB profile directly from the server profile. Server profiles are in the main folder, for example.

 <profile> <id>server.myserver</id> <properties> <jboss.home>D:\Programs\jboss-4.2.1.GA</jboss.home> <server.name>NightlyBuild</server.name> <hosttobind>192.168.1.100</hosttobind> <servlet.port>8080</servlet.port> ... <db>dev02</db> </properties> </profile> 

Both the backend and the database profiles are in the pom submodule of Config, for example.

 <profile> <id>db.dev02</id> <activation> <property> <name>db</name> <value>dev02</value> </property> </activation> <properties> <jdbc.address>jdbc:oracle:thin:@192.168.0.101:1521:dbdev02</jdbc.address> </properties> </profile> 

So, theoretically, since the server.myserver profile sets the db property in dev02 , this should trigger the activation of the db.dev02 profile in the child pump. However, this does not happen. (And if two profiles are in the same pom, btw). If I set the property from the command line using

 mvn -Ddb=dev02 help:active-profiles 

then the profile is activated, although apparently I didn’t write anything.

Did I miss something? Is there any other way to make this work?

I see that there is a similar question: Can I make one maven profile activate another?
However, IMHO this is not a duplicate - I see that my approach does not work, and I would like to understand why. (I read the link, but I might have missed something obvious).

+14
maven-2 profile activation
Feb 11 '10 at 16:48
source share
2 answers

The function simply does not exist. The property activator uses the input properties, not something specified by the profiles (since otherwise he would not know what order to activate them without any more complex logic).

The solution you used has the same properties to activate what you want to do together is the best solution. I understand that this may not always be satisfactory - in this case all you can do is go back to making individual profiles as simple as possible so that you can combine them the way you want on the command line without duplicating each other.

The problem with this function: https://issues.apache.org/jira/browse/MNG-3309
Asset activation issue: https://issues.apache.org/jira/browse/MNG-2276

+16
Feb 11 '10 at 23:24
source share

The MNG-2276 problem mentioned by Brett was resolved in maven 3.x, so now you can define properties in settings.xml for trigger profiles in your pump. Here is an example:

In settings.xml:

 <profile> <id>localDist</id> <activation> <property><name>localDist</name></property> </activation> <properties> <doReleaseTasks>true</doReleaseTasks> </properties> </profile> 

In your pom (or better yet, in your parent pom):

 <profile> <id>doReleaseTasks</id> <activation> <property><name>doReleaseTasks</name></property> </activation> <build> <plugins> ... mvn -DlocalDist will activate these plugins </plugins> </build> </profile> 

It is a good idea to use the forcecer plugin to force mvn 3.0 or more:

 <build> <plugins> <plugin> <artifactId>maven-enforcer-plugin</artifactId> <executions> <execution> <id>enforce-maven</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireMavenVersion> <version>[3.0,)</version> <message> *** Maven 3.x required to allow cascading profiles to be activated in settings.xml (MNG-2276) </message> </requireMavenVersion> </rules> </configuration> </execution> </executions> </plugin> </plugins> </build> 
+3
Jun 10 '14 at 19:03
source share



All Articles