How to refer to maven property in another property?

Suppose I get a properties file from somewhere that defines this:

dog=POODLE 

And when starting maven, I pass a parameter with the name of the property to search for:

 mvn clean install -animal=dog 

I need to get the "POODLE" value in pom.xml without knowing which property to look for (I don't know yet that I'm looking for a "dog", but just now I'm looking for an "animal").

Can this be done?

I can reference in pom ${animal} , which will be replaced by dog , but then I need to see this.

I was innocent enough to try the following, but this will not work:

 ${${animal}} 

Thanks!

+4
source share
1 answer

It should work if you use -Danimal=${dog} . Here is my example

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>nested-property</groupId> <artifactId>nested-property</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <dog>POODLE</dog> </properties> <build> <plugins> <plugin> <groupId>com.soebes.maven.plugins</groupId> <artifactId>maven-echo-plugin</artifactId> <version>0.1</version> <executions> <execution> <phase>install</phase> <goals> <goal>echo</goal> </goals> </execution> </executions> <configuration> <echos> <echo>Animal: ${animal}</echo> </echos> </configuration> </plugin> </plugins> </build> </project> 

run with: mvn -Danimal=${dog} install

leads to

 [INFO] --- maven-echo-plugin:0.1:echo (default) @ nested-property --- [INFO] Animal: POODLE [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ 
+3
source

All Articles