Take the 2-minute tour ×

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


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


And in C:


And I want in A something to define the value of several other properties based on the value of some property. So for example, in pseudocode, A would 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 the mvn clean install referring to A's pom.xml (which contains a module section pointing to B and C), so, as far as I understand, I cannot use profiles for this (since in maven2 projects running in the same reactor inherits the same active profile. I can use maven3, but couldn't find if it changes anything).

Does anyone has any idea how to do this?


share|improve this question

1 Answer 1

up vote 3 down vote accepted

Out of the box, maven can't do this, and workarounds are discouraged (the properties are not supposed to change during the lifecycle).

There are several workarounds though, my favorite being the gmaven plugin, which lets you embed Groovy code in the pom.

The following code snippet will set the property 'abc' to either 'bar' or 'baz', depending on whether the property 'def' contains 'foo':

   pom.properties['def'].contains('foo') ? 'bar' : 'baz';

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

share|improve this answer
It doesn't work perfectly, though. When I wanted to use it so that I could import dependencies with some scope defined by one of the variables I was defining in the validation phase, it broke. I suppose dependency resolution occurs before such script has time to execute. –  Rafael Nov 19 '10 at 19:52
Yes I think so to. to achieve that you'd have to programmatically iterate over the dependencies and replace placeholders with property values ^shudder^. but what you could do is create the dependencies programmatically in the first place. –  Sean Patrick Floyd Nov 19 '10 at 20:01

Your Answer


