Uploaded image for project: 'Maven Shared Components'
  1. Maven Shared Components
  2. MSHARED-437

maven-dependency-tree removes optional flag from managed dependencies

    Details

      Description

      Given the following pom the dependency tree looks like this

      • com.mysema.querydsl:querydsl-core:jar:3.4.3:compile
        • com.google.guava:guava:jar:17.0:compile
        • com.google.code.findbugs:jsr305:jar:2.0.3:compile
        • com.mysema.commons:mysema-commons-lang:jar:0.2.4:compile
        • com.infradna.tool:bridge-method-annotation:jar:1.13:compile

      You expect the entire tree to have the optional flag set to true. But sadly that's not the case. com.google.guava:guava and com.google.code.findbugs:jsr305 are optional = false.

      I found that this is because they are managed dependencies (no difference whether imported or declared directly). When I use this pom it works.

      There are some integration tests in this repository that demonstrate the issue. Checkout demonstrate-tree-bug branch and run "mvn verify". Now compare these files in target/it

      • buck-bom-managed-optional-transitive-dependencies/target/BUCK
      • buck-managed-optional-transitive-dependencies/target/BUCK
      • buck-optional-transitive-dependencies/target/BUCK

      The CI builds demonstrating the failure.

      Let me know if I can help you reproduce the problem.

        Issue Links

          Activity

          Hide
          michael-o Michael Osipov added a comment -

          Arlo Louis O'Keeffe, your issue has been fully resolved on Maven master.

          Show
          michael-o Michael Osipov added a comment - Arlo Louis O'Keeffe , your issue has been fully resolved on Maven master.
          Hide
          michael-o Michael Osipov added a comment - - edited

          Issue fixed partially, remaining bits are in MNG-5935 and MNG-6228.

          Show
          michael-o Michael Osipov added a comment - - edited Issue fixed partially, remaining bits are in MNG-5935 and MNG-6228 .
          Hide
          michael-o Michael Osipov added a comment -

          Arlo Louis O'Keeffe, Robert Scholte, so I applied the patch from Christian:

          [INFO]
          [INFO] --- maven-invoker-plugin:2.0.0:run (integration-test) @ export-dependencies-maven-plugin ---
          [INFO] Building: buck-bom-managed-optional-transitive-dependencies\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.7 s)
          [INFO] Building: buck-bom-managed-single-dependency\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.5 s)
          [INFO] Building: buck-bom-managed-transitive-dependencies\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.5 s)
          [INFO] Building: buck-managed-optional-transitive-dependencies\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.4 s)
          [INFO] Building: buck-managed-single-dependency\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.4 s)
          [INFO] Building: buck-managed-transitive-dependencies\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.5 s)
          [INFO] Building: buck-optional-single-dependency\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.4 s)
          [INFO] Building: buck-optional-transitive-dependencies\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.6 s)
          [INFO] Building: buck-reactor\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.4 s)
          [INFO] Building: buck-single-dependency\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.4 s)
          [INFO] Building: buck-transitive-dependencies\pom.xml
          [INFO] run script postbuild.bsh
          [INFO] ..SUCCESS (1.4 s)
          [INFO] -------------------------------------------------
          [INFO] Build Summary:
          [INFO]   Passed: 11, Failed: 0, Errors: 0, Skipped: 0
          [INFO] -------------------------------------------------
          [INFO]
          [INFO] --- maven-gpg-plugin:1.6:sign (sign-artifacts) @ export-dependencies-maven-plugin ---
          [INFO] ------------------------------------------------------------------------
          [INFO] BUILD SUCCESS
          [INFO] ------------------------------------------------------------------------
          [INFO] Total time: 28.708 s
          [INFO] Finished at: 2017-05-03T18:02:57+02:00
          [INFO] Final Memory: 32M/319M
          [INFO] ------------------------------------------------------------------------
          

          It does indeed solve the issue.

          Arlo Louis O'Keeffe, can you strip down your sample project for us? I'd like fix MNG-5935 with Christian's commit and add your minimal sample project as an IT for that. IT perfectly depicts the issue. I'd appreciate if you could create a PR for the IT. If you need guidance, please ask.

          Show
          michael-o Michael Osipov added a comment - Arlo Louis O'Keeffe , Robert Scholte , so I applied the patch from Christian: [INFO] [INFO] --- maven-invoker-plugin:2.0.0:run (integration-test) @ export-dependencies-maven-plugin --- [INFO] Building: buck-bom-managed-optional-transitive-dependencies\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.7 s) [INFO] Building: buck-bom-managed-single-dependency\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.5 s) [INFO] Building: buck-bom-managed-transitive-dependencies\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.5 s) [INFO] Building: buck-managed-optional-transitive-dependencies\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.4 s) [INFO] Building: buck-managed-single-dependency\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.4 s) [INFO] Building: buck-managed-transitive-dependencies\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.5 s) [INFO] Building: buck-optional-single-dependency\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.4 s) [INFO] Building: buck-optional-transitive-dependencies\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.6 s) [INFO] Building: buck-reactor\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.4 s) [INFO] Building: buck-single-dependency\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.4 s) [INFO] Building: buck-transitive-dependencies\pom.xml [INFO] run script postbuild.bsh [INFO] ..SUCCESS (1.4 s) [INFO] ------------------------------------------------- [INFO] Build Summary: [INFO] Passed: 11, Failed: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------- [INFO] [INFO] --- maven-gpg-plugin:1.6:sign (sign-artifacts) @ export-dependencies-maven-plugin --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 28.708 s [INFO] Finished at: 2017-05-03T18:02:57+02:00 [INFO] Final Memory: 32M/319M [INFO] ------------------------------------------------------------------------ It does indeed solve the issue. Arlo Louis O'Keeffe , can you strip down your sample project for us? I'd like fix MNG-5935 with Christian's commit and add your minimal sample project as an IT for that. IT perfectly depicts the issue. I'd appreciate if you could create a PR for the IT. If you need guidance, please ask.
          Hide
          hudson Hudson added a comment -

          SUCCESS: Integrated in Jenkins build maven-shared #3726 (See https://builds.apache.org/job/maven-shared/3726/)
          MSHARED-437 maven-dependency-tree removes optional flag from managed dependencies

          Pass down #isOptional() to dependency artifact. (michaelo: http://svn.apache.org/viewvc/?view=rev&rev=1793586)

          • (edit) maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
          • (edit) maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
          Show
          hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build maven-shared #3726 (See https://builds.apache.org/job/maven-shared/3726/ ) MSHARED-437 maven-dependency-tree removes optional flag from managed dependencies Pass down #isOptional() to dependency artifact. (michaelo: http://svn.apache.org/viewvc/?view=rev&rev=1793586 ) (edit) maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java (edit) maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
          Hide
          michael-o Michael Osipov added a comment -

          This could also be related to MNG-5935. Can you rebuild Maven with this fix and see wether it solves the issue for you?

          Show
          michael-o Michael Osipov added a comment - This could also be related to MNG-5935 . Can you rebuild Maven with this fix and see wether it solves the issue for you?
          Hide
          michael-o Michael Osipov added a comment -

          Partially fixed with r1793586. Please retest.

          Show
          michael-o Michael Osipov added a comment - Partially fixed with r1793586 . Please retest.
          Hide
          arlol Arlo Louis O'Keeffe added a comment -

          Thanks for the reply, Michael. Sadly updating to 3.0 only makes it worse. Now no dependencies are marked as optional. All four integration tests are failing:

          https://travis-ci.org/evosec/export-dependencies-maven-plugin/jobs/223574750

          [ERROR] The following builds failed:
          [ERROR] *  buck-bom-managed-optional-transitive-dependencies\pom.xml
          [ERROR] *  buck-managed-optional-transitive-dependencies\pom.xml
          [ERROR] *  buck-optional-single-dependency\pom.xml
          [ERROR] *  buck-optional-transitive-dependencies\pom.xml
          

          I believe the problem lies in MavenXDependencyGraphBuilder.getDependencyArtifact(Dependency). The method should not only set the scope but also optional. If possible one can actually completely replace MavenXDependencyGraphBuilder.getDependencyArtifact(Dependency) with RepositoryUtils.toArtifact(Dependency).

          Show
          arlol Arlo Louis O'Keeffe added a comment - Thanks for the reply, Michael. Sadly updating to 3.0 only makes it worse. Now no dependencies are marked as optional. All four integration tests are failing: https://travis-ci.org/evosec/export-dependencies-maven-plugin/jobs/223574750 [ERROR] The following builds failed: [ERROR] * buck-bom-managed-optional-transitive-dependencies\pom.xml [ERROR] * buck-managed-optional-transitive-dependencies\pom.xml [ERROR] * buck-optional-single-dependency\pom.xml [ERROR] * buck-optional-transitive-dependencies\pom.xml I believe the problem lies in MavenXDependencyGraphBuilder.getDependencyArtifact(Dependency). The method should not only set the scope but also optional. If possible one can actually completely replace MavenXDependencyGraphBuilder.getDependencyArtifact(Dependency) with RepositoryUtils.toArtifact(Dependency).
          Hide
          michael-o Michael Osipov added a comment - - edited

          Please update your sample project to version 3.0 and check wether it still fails. DefaultDependencyNode#toNodeString() evaluates the optional flag. It might get lost somewhere.

          Show
          michael-o Michael Osipov added a comment - - edited Please update your sample project to version 3.0 and check wether it still fails. DefaultDependencyNode#toNodeString() evaluates the optional flag. It might get lost somewhere.

            People

            • Assignee:
              michael-o Michael Osipov
              Reporter:
              arlol Arlo Louis O'Keeffe
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development