Experiment with the new catalog feature from Gradle 7, I'm trying to share a catalog via a settings plugin
Unfortunately documentation is quite short on that:
One option to share a catalog is to write a settings plugin, publish it on the Gradle plugin portal or an internal repository, and let the consumers apply the plugin on their settings file.
I initialized via gradle init
for plugin developer using kotlin both as language and build script.
Then I swapped Project
for Settings
and added a dummy alias on producer
class UpgradedOctoGuacamolePlugin : Plugin<Settings> {
override fun apply(settings: Settings) {
settings.dependencyResolutionManagement {
it.versionCatalogs {
it.create("libs") {
it.alias("groovy-core").to("org.codehaus.groovy:groovy:3.0.5")
}
}
}
}
}
On consumer side settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://jitpack.io")
}
versionCatalogs {
create("libs") {
from("com.github.elect86:upgraded-octo-guacamole:9f454a68")
}
}
}
But at the sync
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all artifacts for configuration 'incomingPlatformsForLibs'.
> Could not resolve com.github.elect86:upgraded-octo-guacamole:9f454a68.
Required by:
unspecified:unspecified:unspecified
> No matching variant of com.github.elect86:upgraded-octo-guacamole:9f454a68 was found. The consumer was configured to find attribute 'org.gradle.internal.dm.model.builder.id' with value '0', attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog' but:
- Variant 'apiElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
- Variant 'runtimeElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-runtime' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 46ms
category and usage mismatch, "platform" and "version-catalog" required, but only "library" and "java-api" were found
These are my producer variants
19:15:03: Executing task 'outgoingVariants'...
Type-safe dependency accessors is an incubating feature.
> Task :outgoingVariants
--------------------------------------------------
Variant apiElements
--------------------------------------------------
Description = API elements for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
--------------------------------------------------
Variant runtimeElements
--------------------------------------------------
Description = Elements of runtime for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- Variant : resources
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = resources
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/resources/main (artifactType = java-resources-directory)
(*) Secondary variants are variants created via the Configuration#getOutgoing(): ConfigurationPublications API which also participate in selection, in addition to the configuration itself.
BUILD SUCCESSFUL in 45ms
1 actionable task: 1 executed
19:15:04: Task execution finished 'outgoingVariants'.
What am I doing wrong?
I don't think I have to modify those attributes myself..
Specs:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-milestone-1-all.zip
It turned out I simply had to literally apply the plugin in the settings.gradle.kts
, I didn't know you could do that
apply {
id("guacamole")
}