This message was deleted.
# community-support
s
This message was deleted.
1
n
The producer publishes an artifact variant that contains some extra tooling scripts. In gradle 7 this is defined as follows:
Copy code
val 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.
This worked in gradle 7.x simply through a simple classifier on the produced tooling artifact.
Copy code
val 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:
Copy code
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).
I'm now trying to define a feature variant to select the tooling jar instead. Producer side adds the following:
Copy code
val 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:
Copy code
--------------------------------------------------
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.
The consuming side adds:
Copy code
val withTooling by configurations.creating {
    attributes {
        attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements::class, "tooling-jar"))
    }
}
This passes resolution:
dependencyInsight
output
Copy code
> 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 jar
Nvm, this didn't work in gradle 7 either. I'll have to look at something else. If anyone has some pointers on how to properly configure this in either gradle 8 or 7, that would be appreciated 🙂
v
Looks fine from cursory look I'd say. But if you don't put it on the runtime classpath, it is of course not there. How to do it depends on where you want / need it. If you just need it on the classpath of one specific task, configure that task. If you need it on all runtime classpath, make
runtimeClasspath
extend your created configuration for example.
n
on the consuming side, we have the following to add it to the classpath:
Copy code
configurations.implementation {
    extendsFrom(withTooling)
}
In a build scan, I see the following in the dependencies resolution information:
Copy code
Selection 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?
well, I'm not sure how to interpret it actually. It doesn't report an error during resolution 🤷
v
extendsFrom
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