tony
05/06/2025, 10:31 PMComponentMetadataRule
is the best way to solve it but I can't quite get it to work.
I have a repo publishing a module using Bazel (and a pom file for the metadata) and that module has a dependency on something published from another repo that uses Gradle. The dependency is a test fixture (modeled in Gradle as you'd expect). I have a third module that depends on the Bazel-published module; this third module uses Gradle. Gradle is not able to resolve the transitive test-fixture dependency, failing with an `ArtifactNotFoundException`: it's looking for name-test-fixtures.jar
when it really ought to be looking for name-version-test-fixtures.jar
.
My rule looks like this so far:
class MyRule : ComponentMetadataRule {
override fun execute(context: ComponentMetadataContext) {
context.details.allVariants {
withDependencies {
removeAll { it.module.toString() == "com.squareup.misk:misk-vitess" }
//add("???") // what to add?
}
}
}
now, if I leave it as-is, it happens that compilation succeeds because the test-fixtures module for compilation is also coming into the graph via another path. But this isn't guaranteed so I want to fix this metadata so that compilation will always succeed. But I'm not sure how to re-add the test-fixture variant. In a dependencies block, it would look like testImplementation(testFixtures("com.squareup.misk:misk-vitess:1"))
, but I don't know how to express that (specifically the testFixtures()
part) in the add(...)
method.tony
05/06/2025, 10:39 PM// 1
add("com.squareup.misk:misk-vitess") {
artifactSelectors.add(DefaultDependencyArtifact("", "", null, "test-fixtures", null))
}
but that results in a dependency on the main variant, not the test-fixtures variant.
// 2
add("com.squareup.misk:misk-vitess") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
}
}
but then I get an error:
Cannot select module with conflict on capability 'com.squareup.misk:misk-vitess:0.0-SNAPSHOT' also provided by [com.squareup.misk:misk-v
itess:0.0-SNAPSHOT(runtimeElements), com.squareup.misk:misk-vitess:0.0-SNAPSHOT(apiElements)]
That attribute was selected by looking at the outgoingVariants
of the module with the test-fixtures variant and just picking an attribute that was different:
--------------------------------------------------
Variant runtimeElements
--------------------------------------------------
Runtime elements for the 'main' feature.
Capabilities
- com.squareup.misk:misk-vitess:0.0-SNAPSHOT (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.environment = standard-jvm
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime-jars
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/misk-vitess-0.0-SNAPSHOT.jar (artifactType = jar)
--------------------------------------------------
Variant testFixturesRuntimeElements
--------------------------------------------------
Runtime elements for the 'testFixtures' feature.
Capabilities
- com.squareup.misk:misk-vitess-test-fixtures:0.0-SNAPSHOT
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime
Artifacts
- build/libs/misk-vitess-0.0-SNAPSHOT-test-fixtures.jar (artifactType = jar, classifier = test-fixtures)
I didn't really think setting an attribute would work. What I want to do is set a capability when I'm re-adding the dependency, but the API doesn't appear to allow thattony
05/06/2025, 11:19 PMComponentMetadataRule
. Is that possible?Adam
05/07/2025, 6:25 AMadd("com.squareup.misk:misk-vitess-test-fixtures")
?Thomas Broyer
05/07/2025, 7:30 AMtony
05/07/2025, 5:14 PMtony
05/07/2025, 5:16 PMIt’s worth noting that if the external project is not publishing Gradle Module Metadata, then resolution will fail with an error indicating that such a variant cannot be found:
tony
05/07/2025, 5:20 PMArtifactNotFoundException
is, uh, unexpected. As I said above:
> it's looking for name-test-fixtures.jar
when it really ought to be looking for name-version-test-fixtures.jar
.
I did some debugging in Gradle code and saw a map named allResolvedArtifacts
and saw it had many instances of this artifact, but they all included the version name in the artifact file name. It was only this one case, which came from the bazel metadata, that did not.tony
05/07/2025, 5:26 PMCould not find com.squareup.misk:misk-vitess-test-fixtures:.
I also tried adding a version name (note that we have a bom/platform that ought to supply the version), and got this error instead:
Could not find com.squareup.misk:misk-vitess-test-fixtures:2025.04.30-1746055579-3c9b650-cash
tony
05/07/2025, 5:31 PMArtifactNotFoundException
for the reasons I indicated above (the artifact is missing the version
component from the file name. I think).