Slackbot
07/30/2023, 11:04 AMAdam
07/30/2023, 11:09 AMstd-publishing.gradle.kts
I presume you have something like this?
plugins {
`maven-publish`
}
publishing {
publications.withType<MavenPublication>().configureEach {
pom {
name.convention("my cool library")
description.convention("some description")
// ...
Adam
07/30/2023, 11:13 AMpublishing {
publications {
create<MavenPublication>("maven") {
groupId = "org.gradle.sample"
artifactId = "library"
version = "1.1"
from(components["java"])
}
}
}
Michael Strasser
07/30/2023, 11:39 AMAdam
07/30/2023, 11:40 AMAdam
07/30/2023, 11:48 AMklogging-publishing.gradle.kts
convention already sets the defaults.
The simplest way to update the description is to do it in the actual build.gradle.kts
of each project.
// library-1/build.gradle.kts
plugins {
kotlin("multiplatform")
id("std-publishing")
}
publishing {
// use configureEach {} because Kotlin automatically registers publications
publications.withType<MavenPublication>().configureEach {
pom {
description.set("lib1 desc...") // override the convention plugin default by using `set()`
}
}
}
// library-2/build.gradle.kts
plugins {
`java-library`
id("std-publishing")
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "org.gradle.sample"
artifactId = "library"
version = "1.1"
from(components["java"])
pom {
description.set("lib2 desc...") // override the convention plugin default by using `set()`
}
}
}
My guess is that you’ve already tried to override the convention plugin values in the actual build scripts? But probably these values are being overridden by the convention plugin, which is the opposite of what a convention plugin should do!
So I’d try to fix it by updating this line to use lazy evaluation
publications.withType<MavenPublication>().configureEach {
and use convention()
instead of set()
, so that even if the convention plugin applies defaults to library-1 and library-2, it won’t override anything that the libraries manually set
description.convention("Kotlin logging library with structured logging and coroutines support")
Michael Strasser
07/30/2023, 12:27 PMpublishing {
publications {
create<MavenPublication>("jvm") {
from(components["kotlin"])
pom {
name.set("slf4j-klogging")
description.set("SLF4J provider implemented with Klogging logging library")
}
}
}
}
You can see from this commit:
• There is no change to the convention plugin. The POM specifies values for the Klogging library (KMP plugin), using set()
.
• The build script for the SLF4J provider library (Kotlin JVM plugin) specifies different values, also using set()
. The generated POM contains the desired values.
set()
vs convention()
? It is all part of the great mystery of Gradle to me!Adam
07/30/2023, 12:28 PMI simply added POM specification to the Maven Publication declaration:you made that change in the specific
build.gradle.kts
for the JVM only library?Vampire
07/30/2023, 12:46 PMvsset()
? It is all part of the great mystery of Gradle to me!convention()
Let me demystify it for you. "convention" means it is the conventional default. So if none sets a value explicitly, that value is used and if someone sets
null
as value, also that default value is used. If you use set
, you set the actual value and if you set to null
, it is just that.Michael Strasser
07/30/2023, 1:03 PMbuild.gradle.kts
in the JVM-only library to override the default values, which are for the main library. If I publish another Kotlin Multiplatform library from this repository I might need to do something different.