John
11/11/2025, 6:08 PMoutgoingVariants has this (which is the one I am trying to resolve to)
Secondary Variants (*)
--------------------------------------------------
Secondary Variant archRulesElements
--------------------------------------------------
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = jar
- org.gradle.usage = arch-rules
Artifacts
build/libs/library-with-rules-archrules.jar (artifactType = jar, classifier = archrules)
but when I select
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named<Category>(Category.LIBRARY))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named<Bundling>( Bundling.EXTERNAL))
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named<Usage>( "arch-rules"))
}
it matches no artifacts. any ideas? maybe there is a common gotcha I am missing?John
11/11/2025, 6:10 PMJohn
11/11/2025, 6:10 PMVampire
11/11/2025, 6:18 PMapiElements or runtimeElements is used is defined by the attributes the resolved configuration or artifact view is requesting.
What is the error message you get on trying to resolve.
Here indeed a screenshot might be beneficial to see the colors in the message.John
11/11/2025, 6:19 PMVampire
11/11/2025, 6:20 PMJohn
11/11/2025, 6:23 PMproject.configurations.getByName(sourceSet.runtimeClasspathConfigurationName).attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named<Usage>( "arch-rules"))
}
then resolve the configuration?John
11/11/2025, 6:23 PMCould not determine the dependencies of task ':code-to-check:checkArchRulesMain'.
> Could not resolve all dependencies for configuration ':code-to-check:runtimeClasspath'.
> Could not resolve project :library-with-rules.
Required by:
project ':code-to-check'
> No matching variant of project :library-with-rules was found. The consumer was configured to find a library for use during 'arch-rules', compatible with Java 21, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
- Variant 'apiElements' declares a library, compatible with Java 21, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time and the consumer needed a component for use during 'arch-rules'
- Other compatible attribute:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Variant 'mainSourceElements' declares a component, and its dependencies declared externally:
- Incompatible because this component declares a component of category 'verification' and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about its target Java version (required compatibility with Java 21)
- Doesn't say anything about its usage (required 'arch-rules')
- Variant 'runtimeElements' declares a library, compatible with Java 21, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during runtime and the consumer needed a component for use during 'arch-rules'
- Other compatible attribute:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Variant 'testResultsElementsForArchRulesTest':
- Incompatible because this component declares a component of category 'verification' and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about its target Java version (required compatibility with Java 21)
- Doesn't say anything about its usage (required 'arch-rules')
- Variant 'testResultsElementsForTest':
- Incompatible because this component declares a component of category 'verification' and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about its target Java version (required compatibility with Java 21)
- Doesn't say anything about its usage (required 'arch-rules')Vampire
11/11/2025, 6:24 PMVampire
11/11/2025, 6:24 PMJohn
11/11/2025, 6:24 PMVampire
11/11/2025, 6:24 PMJohn
11/11/2025, 6:25 PMVampire
11/11/2025, 6:25 PMJohn
11/11/2025, 6:25 PMVampire
11/11/2025, 6:25 PMVampire
11/11/2025, 6:25 PMVampire
11/11/2025, 6:26 PMVampire
11/11/2025, 6:26 PMJohn
11/11/2025, 6:27 PM--------------------------------------------------
Variant apiElements
--------------------------------------------------
API elements for the 'main' feature.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = jar
- org.gradle.usage = java-api
Artifacts
- build/libs/library-with-rules.jar (artifactType = jar)
Secondary Variants (*)
--------------------------------------------------
Secondary Variant classes
--------------------------------------------------
Directories containing compiled class files for main.
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = classes
- org.gradle.usage = java-api
Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
--------------------------------------------------
Variant archives
--------------------------------------------------
Configuration for archive artifacts.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Artifacts
- build/libs/library-with-rules.jar (artifactType = jar)
--------------------------------------------------
Variant default
--------------------------------------------------
Configuration for default artifacts.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Artifacts
- build/libs/library-with-rules.jar (artifactType = jar)
--------------------------------------------------
Variant mainSourceElements (i)
--------------------------------------------------
List of source directories contained in the Main SourceSet.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Attributes
- org.gradle.category = verification
- org.gradle.dependency.bundling = external
- org.gradle.verificationtype = main-sources
Artifacts
- src/main/java (artifactType = directory)
- src/main/resources (artifactType = directory)
--------------------------------------------------
Variant runtimeElements
--------------------------------------------------
Runtime elements for the 'main' feature.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime
Artifacts
- build/libs/library-with-rules.jar (artifactType = jar)
Secondary Variants (*)
--------------------------------------------------
Secondary Variant archRulesElements
--------------------------------------------------
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = jar
- org.gradle.usage = arch-rules
Artifacts
- build/libs/library-with-rules-archrules.jar (artifactType = jar, classifier = archrules)
--------------------------------------------------
Secondary Variant classes
--------------------------------------------------
Directories containing compiled class files for main.
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = classes
- org.gradle.usage = java-runtime
Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
--------------------------------------------------
Secondary Variant resources
--------------------------------------------------
Directories containing assembled resource files for main.
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 21
- org.gradle.libraryelements = resources
- org.gradle.usage = java-runtime
Artifacts
- build/resources/main (artifactType = java-resources-directory)
--------------------------------------------------
Variant testResultsElementsForArchRulesTest (i)
--------------------------------------------------
Binary results obtained from running all targets in the 'archRulesTest' Test Suite.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Attributes
- org.gradle.category = verification
- org.gradle.testsuite.name = archRulesTest
- org.gradle.verificationtype = test-results
Artifacts
- build/test-results/archRulesTest/binary (artifactType = directory)
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- junit-10007194369204690871:library-with-rules:unspecified (default capability)
Attributes
- org.gradle.category = verification
- org.gradle.testsuite.name = test
- org.gradle.verificationtype = test-results
Artifacts
- build/test-results/test/binary (artifactType = directory)
(i) Configuration uses incubating attributes such as Category.VERIFICATION.
(*) Secondary variants are variants created via the Configuration#getOutgoing(): ConfigurationPublications API which also participate in selection, in addition to the configuration itself.John
11/11/2025, 6:28 PMproject.plugins.withId("java") {
val ext = project.extensions.getByType<JavaPluginExtension>()
val archRulesSourceSet = ext.sourceSets.create("archRules")
val jarTask = project.tasks.register<Jar>("archRulesJar") {
archiveClassifier.set("archrules")
from(archRulesSourceSet.output)
}
val runtimeElements = project.configurations.getByName("runtimeElements")
runtimeElements.outgoing.variants.create("archRulesElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named("arch-rules"))
}
artifact(jarTask)
}
}John
11/11/2025, 6:29 PMJohn
11/11/2025, 6:29 PMVampire
11/11/2025, 6:38 PMregisterFeature with it to get a feature variant set up. Then you just set the capability to the main capability if you don't want to select by capability but attributes, and I think it should workJohn
11/11/2025, 6:51 PMVampire
11/11/2025, 6:52 PM.plugins you should not use, see its JavaDoc.
You should use .pluginManager.withPlugin instead. 🙂John
11/11/2025, 8:28 PMJohn
11/11/2025, 8:28 PMJohn
11/11/2025, 8:29 PMJohn
11/11/2025, 8:29 PMVampire
11/11/2025, 8:34 PMi was not able to find any auto-generated jar tasksAh right, it is not created for the source set per se, but when you register it as feature variant.
if i make a separate top-level configurationI did not say make a configuration, but register a feature.
Vampire
11/11/2025, 8:41 PMval archRules by sourceSets.registering
java {
registerFeature("archRules") {
usingSourceSet(archRules.get())
capability("$group", name, "$version")
}
}
configurations.named("archRulesRuntimeElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named("arch-rules"))
}
}John
11/11/2025, 8:43 PMVampire
11/11/2025, 8:45 PMJohn
11/11/2025, 8:52 PMJohn
11/11/2025, 8:53 PMJohn
11/11/2025, 8:56 PMVampire
11/11/2025, 9:04 PMJohn
11/11/2025, 10:01 PMJohn
11/11/2025, 10:11 PM