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

Optional true getting lost in managed dependencies when transitive



    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.3.9
    • 3.5.2
    • Dependencies
    • None


      Run 'mvn package' on the project in the attached Parent.zip. Note that the dependency Jar2 gets packaged in WEB-INF/lib and the other dependencies (Jar, Jar1 and Jar3) do not.

      I think the inclusion of Jar2 is incorrect, because project 'Web' declares its dependency on 'Jar' to be optional and Jar2 being a transitive dependency of Jar should inherit this.

      If you look at the other Jarx dependencies, they have different combinations of ways to become optional and have their versions managed. Only the case when optionality is inherited and the dependency management for the version is in another pom, yields incorrect results.

      Please note that I believe the maven-war-plugin is not the cause of this behavior. I have built and used a modified version of maven-war-plugin which as the first thing in its WarMojo.execute() lists the result of getProject().getArtifacts() including the value of each Artifact's isOptional() method. Already at this point only Jar2 has optional false.

      I am using maven-war-plugin in this bug report for the following reasons:

      • maven-war-plugin uses the optional flag of dependencies in deciding whether to package it or not, making this behavior visible
      • I don't know of another way to visualize the value of the optional flag in core maven (running with -X outputs the dependency tree in a section with header 'Dependency collection stats', but this only shows the scope value)
      • maven-dependency-plugin:resolve also only shows scope and not optionality
      • obviously, maven-war-plugin is exactly what I intend to use and where I found the bug


        1. buildoutput.txt
          255 kB
          Marcel Schutte
        2. Parent.zip
          4 kB
          Marcel Schutte

        Issue Links



              michael-o Michael Osipov
              mschutte Marcel Schutte
              0 Vote for this issue
              9 Start watching this issue