Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional tag in dependencyManagement is not inherited #3533

Open
hisener opened this issue Jul 3, 2024 · 2 comments
Open

optional tag in dependencyManagement is not inherited #3533

hisener opened this issue Jul 3, 2024 · 2 comments

Comments

@hisener
Copy link

hisener commented Jul 3, 2024

Describe the bug

The client-java-parent POM has a few "optional" dependencies; however, they are no-ops. For example, the dependency tree of a module that uses io.kubernetes:client-java:jar:19.0.1:

$ mvn dependency:tree
...
[INFO] +- io.kubernetes:client-java:jar:19.0.1:compile
[INFO] |  +- io.prometheus:simpleclient:jar:0.16.0:compile
[INFO] |  |  +- io.prometheus:simpleclient_tracer_otel:jar:0.16.0:compile
[INFO] |  |  |  \- io.prometheus:simpleclient_tracer_common:jar:0.16.0:compile
[INFO] |  |  \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.16.0:compile
[INFO] |  +- io.prometheus:simpleclient_httpserver:jar:0.16.0:compile
[INFO] |  |  \- io.prometheus:simpleclient_common:jar:0.16.0:compile

This is because Maven doesn't take the tag into account. See also https://issues.apache.org/jira/browse/MNG-5227 and https://issues.apache.org/jira/browse/MNG-5632. We noticed this issue, because Coursier seems to take the tag into account unlike Maven.

Could we push optional tags to module POMs and drop them from dependencyManagement?

java/pom.xml

Lines 185 to 190 in d7f9391

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>${prometheus.client.version}</version>
<optional>true</optional>
</dependency>

java/util/pom.xml

Lines 14 to 17 in d7f9391

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
</dependency>

Client Version
19.0.1

Kubernetes Version
1.26.15

Java Version
Java 21

To Reproduce

  1. Create a module that depends on client-java and run mvn dependency:tree. io.prometheus:simpleclient:jar:0.16.0:compile will be listed there.

Expected behavior
Optional dependencies (e.g., io.prometheus:simpleclient) should not be pulled transitively in downstream modules.

KubeConfig
N/A

Server (please complete the following information):
N/A

@hisener hisener changed the title optional tag in dependencyManagement not inherited optional tag in dependencyManagement is not inherited Jul 3, 2024
@brendandburns
Copy link
Contributor

If you move the optional tag into the module pom but you use a central property (e.g. ${prometheus.client.optional}) that is set in a single location, then I think that I'm ok with it. Please also add a comment that references that bug, so that we can remove this when that bug is fixed.

Ultimately, this feels like a bug in maven, so I don't really want to decentralize our pom files just to make up for their bug.

@hisener
Copy link
Author

hisener commented Jul 4, 2024

If you move the optional tag into the module pom but you use a central property (e.g. ${prometheus.client.optional}) that is set in a single location, then I think that I'm ok with it. Please also add a comment that references that bug, so that we can remove this when that bug is fixed.

This works for me.

Ultimately, this feels like a bug in maven, so I don't really want to decentralize our pom files just to make up for their bug.

The question is whether we want these dependencies to be pulled transitively.

  • If so, we should drop optional tags to include them downstream. It's already the case for Maven due to the issue linked above, but Coursier doesn't include them. I don't know the Gradle behavior. Dropping them would make them behave the same.
  • If not, we should apply your suggestion so that they are not included in downstream projects. This could be a breaking change for downstream users that don't depend on these dependencies.

FWIW, google-auth-library-oauth2-http has <optional>true</optional> in both dependencyManagement and dependencies sections.

<optional>true</optional>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants