Assume I get a properties file from somewhere, that has this define:
dog=POODLE
And when running maven, I pass a parameter with the property name to look up:
mvn clean install -animal=dog
I need to be able to retrieve in the pom.xml the value "POODLE"
without knowing what's the property to look up for (I don't know yet that I'm looking up for a "dog", but only that I'm looking up for an "animal").
Can this be done?
I can reference in the pom ${animal}
which will be replaced with dog
, but then I need to look that up.
I was innocent enough to try the following, but it won't work:
${${animal}}
Thanks!
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
results in
[INFO] --- maven-echo-plugin:0.1:echo (default) @ nested-property ---
[INFO] Animal: POODLE
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With