Slackbot
07/25/2023, 9:24 AMNiels Doucet
07/25/2023, 9:25 AMval toolingSourceSet: SourceSet by sourceSets.creating {
compileClasspath = compileClasspath
.plus(sourceSets.main.get().compileClasspath)
.plus(sourceSets.main.get().output)
runtimeClasspath = runtimeClasspath.plus(output).plus(compileClasspath)
java.srcDir(sourceSets.main.get().java)
resources.srcDir("src/main/resources")
resources.srcDir("scripts")
}
val toolingJar by tasks.registering(Jar::class) {
from(toolingSourceSet.output)
archiveClassifier.set("tooling")
}
publishing {
publications {
getByName<MavenPublication>("my-publication") {
artifact(toolingJar)
}
}
}
We consume this library in one of our projects, in such a way that it can be resolved as a regular dependency, as well as through an included build.Niels Doucet
07/25/2023, 9:25 AMval withTooling by configurations.creating
dependencies {
withTooling("producer:my-jar:$myJarVersion:tooling")
}
But the same configuration in gradle 8.2.1 when running a composite build now fails with:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':consumer:generateWithTooling'.
> Could not resolve all task dependencies for configuration ':consumer:runtimeClasspath'.
> Could not find my-jar-tooling.jar (project :producer:my-jar).
Niels Doucet
07/25/2023, 9:25 AMval toolingJars : Configuration by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, JavaVersion.current().majorVersion.toInt())
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements::class,"tooling-jar"))
}
}
artifacts {
add(toolingJars.name, toolingJar)
}
The outgoingVariants
output for this specific artifact looks like this:
--------------------------------------------------
Variant toolingJars
--------------------------------------------------
Capabilities
- producer:my-jar:12.0.129-sha-7ef7d32 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 17
- org.gradle.libraryelements = tooling-jar
- org.gradle.usage = java-runtime
Artifacts
- build/libs/my-jar-12.0.129-sha-7ef7d32-tooling.jar (artifactType = jar, classifier = tooling)
This looks correct to me.Niels Doucet
07/25/2023, 9:26 AMval withTooling by configurations.creating {
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements::class, "tooling-jar"))
}
}
This passes resolution: dependencyInsight
output
> Task :consumer:dependencyInsight
project :producer:my-jar (by composite build)
Variant toolingJars:
| Attribute Name | Provided | Requested |
|--------------------------------|--------------|-------------|
| org.gradle.category | library | |
| org.gradle.dependency.bundling | external | |
| org.gradle.jvm.version | 17 | |
| org.gradle.usage | java-runtime | |
| org.gradle.libraryelements | tooling-jar | tooling-jar |
producer:my-jar:12.0.124 -> project :producer:my-jar
\--- withTooling
Yet the contents of the jar aren't available on the classpath for some reason, as I get a Caused by: java.lang.ClassNotFoundException
for one of the classes inside the tooling jarNiels Doucet
07/25/2023, 11:53 AMVampire
07/25/2023, 5:14 PMruntimeClasspath
extend your created configuration for example.Niels Doucet
07/26/2023, 7:24 AMconfigurations.implementation {
extendsFrom(withTooling)
}
In a build scan, I see the following in the dependencies resolution information:Niels Doucet
07/26/2023, 7:25 AMSelection reason:
Composite build: composite build substitution
Selected variant: toolingJars
Attributes:
org.gradle.category library
org.gradle.dependency.bundling external
org.gradle.jvm.version 17
org.gradle.libraryelements tooling-jar
org.gradle.usage java-runtime (compatible with: java-api)
Requested attributes not found in selected variant:
org.gradle.jvm.environment standard-jvm
Capabilities:
producer:my-jar:12.0.131-sha-3d61849 (not requested)
So it seems like it doesn't "see" the actual tooling jar?Niels Doucet
07/26/2023, 7:27 AMVampire
07/26/2023, 10:45 AMextendsFrom
only extends the declared dependencies, not the attributes on the configuration iirc. You could for example declare the attribute on the actual dependency instead of the configuration on the consumer side