Issue
I am trying to publish a gradle version catalog to mavenLocal repository in order to share versions between multiple projects.
TLDR; project on github publishing of version catalog does not work.
I was doing as described in the official docs.
In my ./gradle folder i have a *.toml file which describes my version catalog.
Importing it successfully works via
// settings.gradle.kts
rootProject.name = "gradle-version-catalogs"
enableFeaturePreview("VERSION_CATALOGS")
dependencyResolutionManagement {
versionCatalogs {
create("quarkus") {
from(files("gradle/quarkus.versions.toml"))
}
}
}
The build script looks like this:
// build.gradle.kts
group = "de.lj"
version = "1.0-SNAPSHOT"
plugins {
`version-catalog`
`maven-publish`
}
publishing {
publications {
create<MavenPublication>("quarkus") {
println("Version Catalogs:")
versionCatalogs.catalogNames.forEach { println(it) }
from(components["versionCatalog"])
}
}
}
Running the gradle publish task results in an artifact de.lj.gradle.version-catalogs:1.0-SNAPSHOT being published to my mavenLocal repository. But there is no de.lj.quarkus which I would like to create.
I am using gradle version 7.3.3 with plugins version-catalog, maven-publish. I pushed my project to github.
Any help is greatly appreciated!
Solution
Solution: The block
// settings.gradle.kts
versionCatalogs {
...
}
is only needed for projects, that IMPORT the published version catalog. It's not needed in the project defining the version catalog. Instead build the version catalog from the *.toml file:
// build.gradle.kts
catalog {
versionCatalog {
from(files("./gradle/quarkus.versions.toml"))
}
}
In order to have a version catalog published to mavenLocal with the Coordinates ${my.groupId}:${my.artifactId}:${my.version} set
// settings.gradle.kts
rootProject.name = "${my.groupId}"
// build.gradle.kts
group = "${my.groupId}"
version = "${my.version}"
Other projects can now reference the versionCatalog with
// settings.gradle.kts
rootProject.name = "version-catalog-import"
enableFeaturePreview("VERSION_CATALOGS")
dependencyResolutionManagement {
repositories {
mavenLocal()
}
versionCatalogs {
create("${my.reference}").from("${my.groupId}:${my.artifactId}:${my.version}")
}
}
// build.gradles.kts
plugins {
`kotlin-dsl`
`version-catalog`
}
dependencies {
implementation(${my.reference})
}
Answered By - code_name
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)