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:
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).