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

List of active profiles defined in ~/.m2/settings.xml gets lost when parsing dependency POMs



    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.2.1, 3.0, 3.0.1, 3.0.2
    • None
    • None
    • Windows, Mac OS X, quite possibly all others
    • Patch



      • root project with two sub projects, test-api and test-impl
      • ~/.m2/settings.xml defines a property in a profile, xxx.
      • root/pom.xml defines a property, yyy, and a profile that defines another property, zzz.
      • test-impl depends on test-api
      • test-api declares a dependency that uses xxx as the groupId, yyy as the artifactId and zzz as the type.
      • Compile the root project with Maven (mvn compile), making sure the profiles are active, one way or another.

      When test-api is compiled, all goes well. When test-impl is compiled, Maven warns of the following:

      [WARNING] The POM for test:test-api:jar:1.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available,
      enable debug logging for more details

      Turning on debuggig (mvn -X compile) prints:

      [WARNING] The POM for test:test-api:jar:1.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available:
      1 problem was encountered while building the effective model for test:test-api:1.0-SNAPSHOT
      [ERROR] 'dependencies.dependency.groupId' for ${xxx}:junit:jar with value '${xxx}' does not match a valid id pattern. @ 

      Apparently, property interpolation failed for xxx but not for yyy or zzz, and xxx fails only when it is referenced in a dependency of the current project. When it is referenced in the current project, it gets properly interpolated.

      What actually happens is that the list of active profiles defined outside the reactor gets lost when resolving dependencies of the current project. They are available when the current project's POM is parsed but not when parsing the POM of the current project's dependencies.

      Now, although this is just a warning in my sample scenario, the consequences in real life are more serious: "no transitive dependencies" means, e.g., modules not compiling that should, or JAR artifacts missing from a WAR artifact, etc., unless the user manually duplicates all the transitive dependencies missed by Maven, in the project that did not compile, or missed a few JAR files from its WAR artifact.

      Attached is a sample multi-module project as described above, a settings.xml file required for the project to compile and a patch that shows how the problem could be eliminated on the maven-3 trunk (http://svn.apache.org/repos/asf/maven/maven-3/trunk).

      The attached sample will give no warning prior to Maven 3.0 but if test-impl were to actually require test-api's dependencies to compile, the problem would surface also with Maven 2.2.1 and possibly earlier.

      I don't think the attached patch is an elegant solution but it has the quality of touching very few files and having little or no side effect other than fixing the problem outlined above. In short, please, make a better fix.


        1. settings.xml
          0.5 kB
          Tibor Adam Varga
        2. root.zip
          4 kB
          Tibor Adam Varga
        3. maven-bug.patch
          3 kB
          Tibor Adam Varga

        Issue Links



              bentmann Benjamin Bentmann
              vta Tibor Adam Varga
              0 Vote for this issue
              1 Start watching this issue