Define properties in maven depending on other property values

I want to create a maven project with the following structure:

A |--pom.xml |--B |--pom.xml |--C |--pom.xml 

where A, B, and C are folders, and B pom.xml and C pom.xml are children of A pom.xml. I want to have the following section in B pom.xml:

 <properties> <some.property>B</some.property> </properties> 

And in C:

 <properties> <some.property>C</some.property> </properties> 

And I want to determine the value of several other properties based on the value of some property. So, for example, in pseudo-code, A will do something like this:

 if ( some.property == 'B') then some.other.property = 'some-value-based-on-b' else if ( some.property == 'C') then some.other.property = 'some-value-based-on-c' ... 

I want to run mvn clean install, referencing A pom.xml (which contains the module section pointing to B and C), so as far as I understand, I canโ€™t use profiles for this (since in maven2 projects in the same reactor the same active profile is inherited.I can use maven3, but could not find if it will change anything).

Does anyone know how to do this?

Thanks,

+4
source share
1 answer

Out of the box, maven cannot do this, and workarounds are not encouraged (properties should not change during the life cycle).

There are some workarounds, although my favorite is the gmaven plugin , which allows you to embed Groovy code in pom .

The following code snippet sets the โ€œabcโ€ property to โ€œbarโ€ or โ€œbazโ€, depending on whether the โ€œdefโ€ property contains 'foo':

 <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> <executions> <execution> <phase>validate</phase> <goals> <goal>execute</goal> </goals> <configuration> <source><![CDATA[ pom.properties['abc']= pom.properties['def'].contains('foo') ? 'bar' : 'baz'; ]]></source> </configuration> </execution> </executions> </plugin> 

BTW, the documents are outdated, the plugin version is now 1.3, and groupId has changed. Here is the current version .

+6
source

All Articles