Recursively defining maven properties

We are trying to regroup our modular maven building. We introduced the DEPLOYMENT_ENV property, which can be "prod", "dev", "staging", or not. The thought we were following was that we could define, say:

dev.jdbc.username = yoyodyne dev.jdbc.password = 0verthruster staging.jdb.username = cavaliers staging.jdbc.password = 8thdim 

If this seems to break, then feed the maven plugin configuration. For example, DBUnit requires a username. The semantic solution that we had in mind was as follows: however, maven does not allow the definition of recursive properties in this way:

 <configuration> <username>${${DEPLOYMENT_ENV}.jdbc.username}</username> </configuration> 

Any ideas for parameterizing maven collectors, so that we can keep our large, huge list of property definitions?

+4
source share
2 answers

Instead of different property names, you can simply use the same properties, but declare them in different profiles, either in pom.xml or in settings.xml

+1
source

Could you learn a little more about the problem you are facing? Do you have any errors?

I already used this definition of a recursive property in one of my pom.xml , in the antrun <configuration> plugin, and it works well:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.2</version> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> ... <ftp server="${my-ftp-url}" userid="${ftp-${appli}-${env}-username}" password="${ftp-${appli}-${env}-password}" remotedir="${remoteDir}/sources" passive="yes"> <fileset dir="../target/"> <include name="*.tar.gz"/> </fileset> </ftp> ... 

As you can see in this code snippet, I use the property ${ftp-${appli}-${env}-username} , where ${appli} , ${env} and ${ftp-xxx-yyy-username} - These are properties that come from the command line or settings.xml .

In any case, as suggested by Yevgeny Kuleshov, I would take a set of <profiles> , which only defines some properties using <properties> tags or an external properties file:

 <build> <plugins> <!-- Properties loader --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <version>1.0-alpha-1</version> <executions> <execution> <phase>initialize</phase> <goals> <goal>read-project-properties</goal> </goals> <configuration> <files> <file>${basedir}/${env-properties-file}</file> </files> </configuration> </execution> </executions> </plugin> </plugins> </build> ... <profiles> <!-- Development --> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> <property> <name>env</name> <value>dev</value> </property> </activation> <properties> <env-properties-file>dev-environment.properties</env-properties-file> </properties> </profile> <!-- Homologation --> <profile> <id>hom</id> <activation> <activeByDefault>false</activeByDefault> <property> <name>env</name> <value>hom</value> </property> </activation> <properties> <env-properties-file>homologation-environment.properties</env-properties-file> </properties> </profile> ... 
+1
source

All Articles