Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-4565

Requiring multiple profile activation conditions to be true does not work

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 3.2.1
    • Fix Version/s: 3.2.2
    • Component/s: Profiles
    • Labels:
      None
    • Environment:
      All platforms.

      Description

      According to the documentation at http://www.sonatype.com/books/mvnref-book/reference/profiles-sect-activation.html a profile is activated when all activation conditions are met (which makes sense of course). But when I try to use this it does not work. It seems maven does an OR instead of an AND (which is not rearly as useful and is the opposite of what the documentation says at the previous link).

      For example, if I have one profile that is activated like this:

               <activation>
                  <activeByDefault>false</activeByDefault>
                  <os>
                     <name>linux</name>
                  </os>
               </activation>

      and another profile that is activated like this:

              <activation>
                  <activeByDefault>false</activeByDefault>
                  <os>
                     <name>linux</name>
                  </os>
                  <property>
                      <name>release</name>
                      <value>true</value>
                  </property>
               </activation>

      Then I would expect the second profile to only be activated if the OS is linux and the release property is defined.

      When I run 'mvn help:active-profiles' however, maven shows that both profiles are active even though the release property is not defined.

        Issue Links

          Activity

          Hide
          jonenst Jon Harper added a comment -

          So now the program behavior is different before and after maven 3.2.2.
          Do we have to wait 10 years until maven 3.2.1 (2014-02-21) does not need to be supported anymore ?
          Or is there a usable workaround today ? ( maybe a system property holding the maven version to be used in profile activation, or something else ?)

          Show
          jonenst Jon Harper added a comment - So now the program behavior is different before and after maven 3.2.2. Do we have to wait 10 years until maven 3.2.1 (2014-02-21) does not need to be supported anymore ? Or is there a usable workaround today ? ( maybe a system property holding the maven version to be used in profile activation, or something else ?)
          Hide
          stephan202 Stephan Schroevers added a comment -

          Luc Chapon, see c652993. Indeed, OR semantics were simply replaced with AND semantics. Though this is an improvement in the common case, it's a shame that the previous behavior was lost completely.

          Show
          stephan202 Stephan Schroevers added a comment - Luc Chapon , see c652993 . Indeed, OR semantics were simply replaced with AND semantics. Though this is an improvement in the common case, it's a shame that the previous behavior was lost completely.
          Hide
          Sxilderik Luc Chapon added a comment -

          fixed how ? added <and> and <or> ? turned everything and ?
          Where can we see the fix comments ?
          thanks !

          Show
          Sxilderik Luc Chapon added a comment - fixed how ? added <and> and <or> ? turned everything and ? Where can we see the fix comments ? thanks !
          Hide
          wqtasf Ric Wang added a comment -

          I am new, and don't know who wrote the book of http://www.sonatype.com/books/mvnref-book/reference/profiles-sect-activation.html

          From the official Maven pages, though, I don't see the "all" part on the activation conditions. It may be OK to have the "all" and "AND" on the conditions as the default behavior (even that's debateable), but the so called "fix" simply took away the previous "OR" feature, and changed it into an "AND": That is no really a "fix", but a feature change which is not really sensible.

          Show
          wqtasf Ric Wang added a comment - I am new, and don't know who wrote the book of http://www.sonatype.com/books/mvnref-book/reference/profiles-sect-activation.html From the official Maven pages, though, I don't see the "all" part on the activation conditions. It may be OK to have the "all" and "AND" on the conditions as the default behavior (even that's debateable), but the so called "fix" simply took away the previous "OR" feature, and changed it into an "AND": That is no really a "fix", but a feature change which is not really sensible.
          Hide
          jvanzyl Jason van Zyl added a comment -

          Fixed on c6529932f9e3efdfc86ed73f59a307a8f8b6ea5f

          Show
          jvanzyl Jason van Zyl added a comment - Fixed on c6529932f9e3efdfc86ed73f59a307a8f8b6ea5f
          Hide
          mysterion Konstantin Perikov added a comment -

          I've create pull request for this functionality - https://github.com/apache/maven/pull/16

          Show
          mysterion Konstantin Perikov added a comment - I've create pull request for this functionality - https://github.com/apache/maven/pull/16
          Hide
          sebb@apache.org Sebb added a comment -

          The Sonatype book still says that activation conditions are ANDed

          http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html#profiles-sect-activation-config

          "A profile is activated when all activation criteria has been satisfied." (sic)

          Still broken in Maven 3.0.5

          Show
          sebb@apache.org Sebb added a comment - The Sonatype book still says that activation conditions are ANDed http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html#profiles-sect-activation-config "A profile is activated when all activation criteria has been satisfied." (sic) Still broken in Maven 3.0.5
          Hide
          john.j.cool Ronny Pscheidl added a comment -

          This extension should solve the problem when all activation conditions are met:

          https://github.com/johnjcool/and-activation-profile-selector

          Show
          john.j.cool Ronny Pscheidl added a comment - This extension should solve the problem when all activation conditions are met: https://github.com/johnjcool/and-activation-profile-selector
          Hide
          pekarna Ondra Žižka added a comment -

          Seems that Karel's extension solves MNG-5194.

          Show
          pekarna Ondra Žižka added a comment - Seems that Karel's extension solves MNG-5194 .
          Hide
          kapy Karel Piwko added a comment -

          Guys, you can check following Maven extension https://github.com/kpiwko/el-profile-activator-extension.

          You just drop two jars into $MAVEN_HOME/lib/ext and you'll get MVEL support in <property> value.

          Show
          kapy Karel Piwko added a comment - Guys, you can check following Maven extension https://github.com/kpiwko/el-profile-activator-extension . You just drop two jars into $MAVEN_HOME/lib/ext and you'll get MVEL support in <property> value.
          Hide
          ebann Ivan added a comment -

          What is the status of that fix ?

          Show
          ebann Ivan added a comment - What is the status of that fix ?
          Hide
          hhuynh Hung Huynh added a comment -

          supporting for both "AND" and "OR" logic would be greatly useful

          Show
          hhuynh Hung Huynh added a comment - supporting for both "AND" and "OR" logic would be greatly useful
          Hide
          epabst Eric Pabst added a comment - - edited

          I have a fix for this here that doesn't modify the pom schema at all and simply switches it from an OR to and AND:
          https://github.com/epabst/maven-3/tree/MNG-4516

          Show
          epabst Eric Pabst added a comment - - edited I have a fix for this here that doesn't modify the pom schema at all and simply switches it from an OR to and AND: https://github.com/epabst/maven-3/tree/MNG-4516
          Hide
          pgoodwine Peter Goodwine added a comment -

          Settings Reference:

          Activation occurs when all specified criteria have been met, though not all are required at once.

          Contradicts the POM reference, worse than "not really useful"

          Show
          pgoodwine Peter Goodwine added a comment - Settings Reference : Activation occurs when all specified criteria have been met, though not all are required at once. Contradicts the POM reference, worse than "not really useful"
          Hide
          clemens Clemens Fuchslocher added a comment -

          An and element would be useful:

          <activation>
          	<activeByDefault>false</activeByDefault>
          	<and/>
          	<os>
          		<name>linux</name>
          	</os>
          	<property>
          		<name>release</name>
          		<value>true</value>
          	</property>
          </activation>
          
          Show
          clemens Clemens Fuchslocher added a comment - An and element would be useful: <activation> <activeByDefault>false</activeByDefault> <and/> <os> <name>linux</name> </os> <property> <name>release</name> <value>true</value> </property> </activation>
          Hide
          clemens Clemens Fuchslocher added a comment -

          This was introduced by MNG-3106:

          The new behaviour is that the profile will be activated if any of the activators returns true (i.e. an "or" operation).

          Show
          clemens Clemens Fuchslocher added a comment - This was introduced by MNG-3106 : The new behaviour is that the profile will be activated if any of the activators returns true (i.e. an "or" operation).
          Hide
          clemens Clemens Fuchslocher added a comment -

          POM Reference:

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

          Not really useful.

          Show
          clemens Clemens Fuchslocher added a comment - POM Reference : Activation occurs when one or more of the specified criteria have been met. When the first positive result is encountered, processing stops and the profile is marked as active. Not really useful.

            People

            • Assignee:
              jvanzyl Jason van Zyl
              Reporter:
              nickallen Nicholas Allen
            • Votes:
              57 Vote for this issue
              Watchers:
              44 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development