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

Fix transitive dep resolution when exclusion is present in other POM #919

Merged
merged 7 commits into from
Jun 22, 2023

Conversation

artem-zinnatullin
Copy link
Contributor

@artem-zinnatullin artem-zinnatullin commented Jun 21, 2023

#908 uncovered a bug in coursier which leads to transitive dep not being resolved if an exclusion rule for it is present in POM of a non-related dependency.

This PR adds a regression test and a fix by @rdesgroppes.

TL;TR:

  1. mockito-core depends on byte-buddy
  2. androidx.arch.core:core-testing POM has exclusion for <groupId>net.bytebuddy</groupId>
  3. If both are present in maven_install then mockito-core doesn't get its byte-buddy dependency
  4. If androidx.arch.core:core-testing is removed from maven_install then mockito-core gets byte-buddy dependency
  5. Adding byte-buddy manually to maven_install doesn't help
  6. mockito-core was getting byte-buddy dependency with androidx.arch.core:core-testing in maven_install prior to change Add preliminary support for exe packaging type #908
  7. This is likely a bug in coursier due to how Add preliminary support for exe packaging type #908 passes classifier and type for dependency resolution

This reverts commit 36e730e.
This reverts commit 61a83ff.
},
"org.openjfx:javafx-base": {
"shasums": {
"jar": "c5084a74417a89c69a0c122fae96a4b70bf619fc3d6218ea102a4047ec85ad04",
"linux": "2ebf6fa2cbbe1c8b4f7780e06e97beb038f644d5ecf9f15a41c5e88ee0ef9cf1"
"mac": "2d8052a08fd2e5d98e1d5a16d724ea5dd02102879de20a193225f57199803983"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate, but I don't have a Linux machine/image with all required Bazel deps to regenerate this for Linux and have matching hashes

@@ -257,6 +257,10 @@ maven_install(
# Any two platforms to ensure that it doesn't work _only_ under the host operating system
"com.google.protobuf:protoc:exe:linux-x86_64:3.21.12",
"com.google.protobuf:protoc:exe:osx-aarch_64:3.21.12",
# https://github.com/bazelbuild/rules_jvm_external/issues/917
# androidx core-testing POM has "exclusion" for "byte-buddy" but it should be downloaded as mockito-core dependency.
"org.mockito:mockito-core:jar:3.3.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since jar is the default, it's usually omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep yep, it's just a convention in our large Android monorepo to see what deps are JVM and what are Android AARs I think it's fine for purpose of this regression test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

Comment on lines +262 to +263
"org.mockito:mockito-core:jar:3.3.3",
"androidx.arch.core:core-testing:aar:2.1.0",
Copy link
Contributor

@rdesgroppes rdesgroppes Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave a try with these 2 artifacts exactly as written above and indeed faced the issue that net.bytebuddy:byte-buddy and net.bytebuddy:byte-buddy-agent were missing from mockito-core's transitive dependencies.
It turns out that, despite the theoretical equivalence, stripping out the jar packaging type leads to the intended behavior.

-        "org.mockito:mockito-core:jar:3.3.3",
+        "org.mockito:mockito-core:3.3.3",
         "androidx.arch.core:core-testing:aar:2.1.0",

(just FYI, not to be merged)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artem-zinnatullin I just filed artem-zinnatullin#1 you may merge to your branch or not, at your convenience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged!

It's still unclear why Coursier behaves differently whether being passed
`some:artifact:version,type=jar` or just `some:artifact:version` since
they're theoratically equivalent, but this anyway removes a redundancy.
@rdesgroppes
Copy link
Contributor

Closes #917.

Do not append `,type=jar` to `coursier fetch`ed artifacts
@artem-zinnatullin artem-zinnatullin changed the title Add regression test for failed transitive dep #917 Fix transitive dep resolution when exclusion is present in other POM Jun 21, 2023
@artem-zinnatullin
Copy link
Contributor Author

Merged your fix and updated PR title and description for the fix and test to be ready for merge!

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for the PR!

@@ -258,7 +258,7 @@ json = struct(
#
def _artifact_to_coord(artifact):
classifier = (",classifier=" + artifact["classifier"]) if artifact.get("classifier") != None else ""
type = (",type=" + artifact["packaging"]) if artifact.get("packaging") != None else ""
type = (",type=" + artifact["packaging"]) if artifact.get("packaging") not in (None, "jar") else ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

@shs96c shs96c merged commit 8678af1 into bazel-contrib:master Jun 22, 2023
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants