Maven & # 8594; profile & # 8594; activation - all conditions are required or only one?

Configuration:
- Maven: 3.0.5
- Java: 1.6.0_45

Description:

Say we have a profile configuration as shown below:

<profiles> <profile> <id>profile-1</id> <activation> <jdk>1.6</jdk> <property> <name>name</name> <value>Hubert</value> </property> </activation> </profile> <profile> <id>profile-2</id> <activation> <jdk>1.6</jdk> <property> <name>name</name> <value>Wiktoria</value> </property> </activation> </profile> </profiles> 

We have two profiles: profile-1 and profile-2.

Profile-1 profile must be active when two requirements are met:
- jdk - version 1.6
- property name is Hubert

Question:

Check out this configuration:

mvn -Dname = Hubert Help: Active Profiles

The result is that there are two active profiles: profile-1 and profile-2.
Hm ...
Profile-2 profile should not be active, since the property name has a value different from what Wiktoria expected.

Can someone explain to me why this works? Is this normal behavior?
Thanks.

+7
java maven maven-3
source share
2 answers

The problem is that the activation list with your launch conditions is associated with OR . They have a ticket to provide multiple activation triggers , but it is still open. This means that it matches your sdk rule, which is true and therefore active.

 <profile> <id>profile-1</id> <activation> <!-- true || true = true --> <jdk>1.6</jdk> <!-- true --> <property> <!-- true --> <name>name</name> <value>Hubert</value> </property> </activation> </profile> <profile> <id>profile-2</id> <activation> <!-- true || false = true --> <jdk>1.6</jdk> <!-- true --> <property> <!-- false --> <name>name</name> <value>Wiktoria</value> </property> </activation> </profile> 
+6
source share

NOTE: This is only an addition to Chasmo's correct answer.

There is a sonata book describing Maven. In the section of the book of the sonatype (section 5.3.1) we can find:

The profile is activated when all activation criteria are met.

This is not true. The truth is that to activate the profile, one condition is enough, which, of course, is equal to the logical condition OR. This behavior is described in Maven docs :

Activation occurs when one or more of these criteria are met. When the first positive result occurs, processing stops and the profile is marked as active.

This is neither intuitive nor very useful to me. But this is how maven works while writing this.

There is an MNG-4565 flag for AND. This is flagged as a bug, but according to the Maven doc it is not, so this ticket has been open for almost 4 years. The most useful part is the last comment on this ticket written by Ronnie Pshaidl. His comment points to this source: and-activation-profile-selector . This changes the default maven condition for the AND condition. Checked. Working. But of course, if you decide to use this, you have one more thing to keep in mind.

+2
source share

All Articles