Skip to content

[MNG-5227] The 'optional' flag of a dependency should be manageable. #6974

Open

Description

@jira-importer

Christian Schulte opened MNG-5227 and commented

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>groupId</groupId>
      <artifactId>artifactId</artifactId>
      <version>version</version>
      <optional>false</optional> <!-- Ignored by Maven 2 & 3 in dependency management. -->
    </dependency>
  </dependencies>
</dependencyManagement>

Affects: 3.0.3

Attachments:

Issue Links:

  • MRESOLVER-9 DefaultDependencyCollector does not correctly handle dependency management
    ("is blocked by")

  • MNG-5632 Optional tag in dependencyManagement not inherited - disallow and/or document
    ("is duplicated by")

  • HIVE-27338 JDBC drivers are transitively inherited although declared optional
    ("causes")

  • MNG-5600 Dependency management import should support exclusions.

  • MNG-2984 Allow more control around the configuration and use of optional dependencies

  • MNG-6139 Addition of command line option 'legacy-dependency-management'.
    ("is required by")

  • MNG-4600 [regression] Optional flag from dependency management applied to dependencies
    ("supercedes")

  • MNG-1977 Global dependency exclusions
    ("supercedes")

  • MNG-5959 Can maven provide a features that exclude dependency gloablly
    ("supercedes")

  • MNG-5935 Optional true getting lost in managed dependencies when transitive
    ("is depended upon by")

Remote Links:

6 votes, 14 watchers

Activity

  1. jira-importer commented on Jan 27, 2016

    @jira-importer
    Author

    Christian Schulte commented

    This has been solved in Aether but not in Maven.

  2. jira-importer commented on Jan 27, 2016

    @jira-importer
    Author
  3. jira-importer commented on Jan 28, 2016

    @jira-importer
    Author

    Christian Schulte commented

    This issue is blocked by Aether Bug 486740.

  4. jira-importer commented on Jan 28, 2016

    @jira-importer
    Author

    Jason van Zyl commented

    I applied your patch locally, but I can't push because Eclipse's webhook's have detected you don't have an Eclipse CLA on file. So, I started the termination process with Eclipse, and I am working with Joel from Sonatype so I can push the code to Github in the interim and cut a release to Maven Central to unblock this. Bear with me.

  5. jira-importer commented on Jan 31, 2016

    @jira-importer
    Author

    Christian Schulte commented

    Let me know if I there is anything I can do to help. Does it mean you are planning to change the Aether package names? We had 'org.sonatype.aether' and 'org.eclipse.aether' maybe it's time someone registers a 'aether.codes', 'aether.software' or whatever domain name and we use that for the package name once and for all? Maybe even rename the whole thing?

  6. jira-importer commented on Jan 31, 2016

    @jira-importer
    Author

    Jason van Zyl commented

    No, I definitely do not want to rename the packages. It caused so much disruption that I really don't think it's worth it. Once it's entirely internalized it won't really matter so I don't see much point in causing a lot of grief. I'm working with the Eclipse Foundation on the termination of Aether and I don't think anyone is going to mind if we leave the package names as they are. I really don't see it as value-adding work to flip a bunch of package names and make adapters for everything. Should have a release out in a day or two.

  7. jira-importer commented on Jan 31, 2016

    @jira-importer
    Author

    Christian Schulte commented

    I would not mind signing a CLA with Eclipse if that helps. No experience with any processes there, though.

  8. jira-importer commented on Jan 31, 2016

    @jira-importer
    Author

    Jason van Zyl commented

    It's a little more complicated at Eclipse because your employer has to sign the corporate CLA. This usually takes a while, and honestly we're transitioning this back to Apache so I'll have something for you in Maven Central in a day or two.

  9. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Jason van Zyl commented

    Christian Schulte There's no real need for a CLA at Eclipse because you have one at Apache. But I would ask that add a test for https://github.com/jvanzyl/aether-core/commit/da9708bf7321e25c2a74dddb893539f735135a6d. Also the ITs appear to be broken, do they depend on this change?

    I will fill out the termination review paperwork today, ask Eclipse legal to verify my license change, and ask if we can continue to use their package names at Apache to prevent any unnecessary pain for users. I'll try to get this into Apache as fast as possible.

  10. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Jason van Zyl commented

    Do you have corresponding changes in Maven core as the use of Aether with your patch causes a failure in Maven core for me?

  11. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Christian Schulte commented

    The ITs have been committed already. They will start working with the updated Aether automatically.

  12. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Christian Schulte commented

    If you are referring to 'maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java' then this test case needs updating. It's testing the existence of a transitive test dependency which should not be there. The scope in dependency management needs updating from 'test' to something available transitively to make it test what was intended. I've written test cases for 'maven-core' as well.

  13. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Jason van Zyl commented

    But it is there, and you can't just arbitrarily change the behaviour. How do you know this won't affect anyone? You make a change in Aether with no tests, commit changes to ITs that fail without those changes in Aether, Maven core fails with the changes in Aether and then you assert the test needs to change? C'mon Christian, you can't do that.

  14. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Christian Schulte commented

    Test case update.

  15. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Christian Schulte commented

    That test case is testing the correct version is inherited and is not about anything scope. The author did not notice he is running into a Maven core issue. Please see the patch and tell me the test case is testing correct behaviour when not applied.

  16. 12 remaining items

  17. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Joerg Schaible commented

    Sounds reasonable.

  18. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Joerg Schaible commented

    I am not so sure about this. It would allow to cut an artifact out of the dependency tree, e.g. in case G:A has been changed or it is included in the Java runtime now. However, it is also a great tool to shoot yourself into the foot ;-)

  19. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Christian Schulte commented

    See Aether Bug 398572.

    Pretty much all aspects of a dependency can be controlled via a DependencyManager, but the optional flag not. Pure oversight.

    The optional flag is broken/useless if you cannot manage it. Managing 'optional' to 'true' is the same as excluding that dependency everywhere. In dependency management you can omit the version. That's the missing 'global exclude' feature. If you happen to depend on some project with dependencies flagged optional, you can globally select them without having to care about the version in dependency management. Pure oversight.

  20. jira-importer commented on Feb 3, 2016

    @jira-importer
    Author

    Christian Schulte commented

    Maybe some code helps demonstrating the issue behind this. In MavenRepositorySystemUtils you have

    101         DependencySelector depFilter =
    102             new AndDependencySelector( new ScopeDependencySelector( "test", "provided" ),
    103                                        new OptionalDependencySelector(), new ExclusionDependencySelector() );
    104         session.setDependencySelector( depFilter );
    

    The 'ScopeDependencySelector' is setup to exclude transitive dependencies with scope "test" or "provided". The fix to Aether will stop Aether from returning transitive 'test' scope dependencies. The 'OptionalDependencySelector' is setup to exclude transitive dependencies with 'optional' set to 'true'. The fix to Aether will stop Aether from returning optional transitive dependencies.

  21. jira-importer commented on Feb 4, 2016

    @jira-importer
    Author

    Hervé Boutemy commented

    changed the issue type from "Bug" to "New Feature", since it's not really a bug: this has been done intentionally in MNG-4600, and the change is expected to bring new feature (I still need to dig deeper into the issue to make my own idea on this new feature)

  22. jira-importer commented on Jan 9, 2017

    @jira-importer
    Author

    Stephen Connolly commented

    Maven 3.4.0 has been dropped. See this thread for more details.

    This issue will need to be re-scheduled for a Maven release in the (hopefully near) future.

  23. jira-importer commented on Mar 25, 2017

    @jira-importer
    Author

    Christian Schulte commented

    Issue is fixed in the master branch of my private maven repository on github. When interested, you can cherry pick the commit to your own repository and create a pull request for the apache master branch with just this commit yourself from there.

  24. jira-importer commented on May 16, 2017

    @jira-importer
    Author

    Michael Osipov commented

    Unfornuately, the IT does not pass and I haven't received an answer to my question by the implementor of the IT.

  25. jira-importer commented on May 11, 2023

    @jira-importer
    Author

    Stamatis Zampetakis commented

    I hit this problem today in the Apache Hive project. To avoid licensing problems we declared all JDBC driver dependencies as runtime and optional in the dependencyManagement section (https://github.com/apache/hive/blob/47c784b46a951d4ee9ce2712f62aa6af92b71395/pom.xml#L1336). It took me a while to understand that actually the optional declaration in dependencyManagement is ignored cause for some reason the maven dependency plugin was showing that the dependency is optional when running the dependency:tree.

    Contrary to what others may think I would argue that this is a bug not a new feature. If optional is the only thing that is not handled in the dependencyManagement section then this is quite unexpected. I think it definitely deserves a mention in the documentation till this issue is fixed.

    Are there any plans to include this in the next 4 release? Can I help with something to move this forward.

  26. jira-importer commented on Feb 3, 2025

    @jira-importer
    Author

    Guillaume Nodet commented

    It should be a matter of reverting:

    Well, the second commit is the IT which should be fixed and not removed.

    Any takers ?

  27. added
    enhancement
    priority:minor
    on Jul 6, 2025
  28. modified the milestones: , 4.x on Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:minor

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions