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

CLI cannot deactivate a profile that's activated in POM via <activeByDefault>

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.0.9
    • None
    • Profiles
    • None

    Description

      Consider the following POM:

      <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>test</groupId>
        <artifactId>test</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>test</name>
        <url>http://maven.apache.org</url>
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
          </dependency>
        </dependencies>
      
        <profiles>
          <profile>
            <id>yuck</id>
            <activation>
              <activeByDefault>true</activeByDefault>
            </activation>
            <build>
              <plugins>
                <plugin>
                  <groupId>no-such-plugin</groupId>
                  <artifactId>just-to-cause-error</artifactId>
                </plugin>
              </plugins>
            </build>
          </profile>
        </profiles>
      </project>
      

      I'd like to deactivate the "yuck" profile that kicks in by default. I cannot do this even if I run "mvn -P -yuck".

      This is because the DefaultProfileManager.getActiveProfiles() is implemented as follows:

          public List getActiveProfiles()
              throws ProfileActivationException
          {
              List activeFromPom = new ArrayList();
              List activeExternal = new ArrayList();
      
              for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
              {
                  Map.Entry entry = (Entry) it.next();
      
                  String profileId = (String) entry.getKey();
                  Profile profile = (Profile) entry.getValue();
      
                  boolean shouldAdd = false;
                  if ( activatedIds.contains( profileId ) )
                  {
                      shouldAdd = true;
                  }
                  else if ( !deactivatedIds.contains( profileId ) && isActive( profile ) )
                  {
                      shouldAdd = true;
                  }
      
                  if ( shouldAdd )
                  {
                      if ( "pom".equals( profile.getSource() ) )
                      {
                          activeFromPom.add( profile );
                      }
                      else
                      {
                          activeExternal.add( profile );
                      }
                  }
              }
      
              if ( activeFromPom.isEmpty() )
              {
                  for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
                  {
                      String profileId = (String) it.next();
      
                      Profile profile = (Profile) profilesById.get( profileId );
      
                      activeFromPom.add( profile );
                  }
              }
      
              List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
      
              allActive.addAll( activeExternal );
              allActive.addAll( activeFromPom );
      
              return allActive;
          }
      

      ... and therefore the defaultIds set (which contains "yuck") is considered active, even if deactivatedIds contain them. The fix should be obvious by now.

      Attachments

        Issue Links

          Activity

            People

              bentmann Benjamin Bentmann
              kohsuke Kohsuke Kawaguchi
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: