I have this recollection that Gradle doesn't provi...
# plugin-development
t
I have this recollection that Gradle doesn't provide any way to access an artifact classifier via a public API. Am I wrong about that? This has to do with the Dependency Analysis Plugin. It has a "coordinates" concept for modeling a dependency as a unique identity, but currently doesn't account for classifiers at all, which keeps leading to annoying bugs.
o
If you're looking via an ExternalModuleDependency, call getArtifacts and check https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/DependencyArtifact.html#getClassifier()
t
Does the plugin correctly detects variants? Classifiers are a Maven thing, that Gradle decided to model as variants instead (and features), with the expectation that you'd declare the appropriate metadata rule to model the variants for that dependency and attach the appropriate artifact (based on the naming rule used by Maven with classifiers)
o
Gradle doesn't synthesize or map classifiers to variants on the resolution side though, so a plugin that wants to do analysis on dependencies without Gradle Module Metadata needs to inspect classifiers still.
t
to make this concrete:
Copy code
~/.gradle/caches/modules-2/files-2.1/org.threeten/threetenbp/1.6.0
$ tree .
.
├── 146819e1d5a2145828fd7b5fa8338decc8c1fa5e
│   └── threetenbp-1.6.0.jar
├── 87d48dfa799db47b7b92f835289b831a43559c07
│   └── threetenbp-1.6.0-javadoc.jar
├── aac77c858d5205f899ec7c0dab7d05d703c78c15
│   └── threetenbp-1.6.0-sources.jar
├── eb2bb065c90fb047b794b6288be2a0dda9d5fe0a
│   └── threetenbp-1.6.0.pom
└── f9b092d060e03a9fc0b7bc21151b2e2483cd11c0
    └── threetenbp-1.6.0-no-tzdb.jar
org.threeten:threeten
is only published with POM metadata, and it has a no-classifier "variant" and a
-no-tzdb
"variant." But this is "the same dependency", just with two artifacts. I need a way to differentiate the artifacts. I currently model a dependency's "coordinates" as basically GAV + capabilities + attributes. So basically, I want to add the classifier to this model. Octavia, thanks for that pointer, I'll take a look.
It's nice to know I'm not the only one who struggles with this. Here's a screencap from Android Studio getting it wrong. I assume this is actually a bug in the foundational Intellij platform but haven't checked yet. Or maybe it's a bug in the Tooling API? I changed my dependency declaration from
testImplementation("org.threeten:threetenbp:1.6.0")
to
testImplementation("org.threeten:threetenbp:1.6.0:no-tzdb")
, synced, and then changed it back and synced again. Intellij thinks it only has access to the
no-tzdb
variant, and even shows me "red code" in my Java source. However, builds succeed, showing that Gradle is correctly resolving the base (no classifier) variant.
@Octavia Togami under what circumstances would a dependency like this have zero artifacts? I'm debugging some code and even though I have a ModuleDependency for a library that I know has multiple artifacts (the threeten one discussed above), during debugging
getArtifacts()
is returning an empty set.
o
I believe that is typically the case, as the implicit artifact used is not shown as part of the set, so most normally declared dependencies without a classifier don't have one.
t
that brings me back to my original question. Is there then no reliable way to check if a dependency has a classifier?