Migrate to new central publish

This commit is contained in:
Alexander Nozik 2024-12-19 20:45:45 +03:00
parent a6a1ed4102
commit e1c946cd8f
6 changed files with 62 additions and 129 deletions

View File

@ -1,43 +0,0 @@
import kotlin.io.path.readText
job("Build") {
gradlew("openjdk:11", "build")
}
job("Publish"){
startOn {
gitPush { enabled = false }
}
container("openjdk:11") {
env["SPACE_USER"] = Secrets("space_user")
env["SPACE_TOKEN"] = Secrets("space_token")
kotlinScript { api ->
val spaceUser = System.getenv("SPACE_USER")
val spaceToken = System.getenv("SPACE_TOKEN")
// write version to the build directory
api.gradlew("version")
//read version from build file
val version = java.nio.file.Path.of("build/project-version.txt").readText()
api.space().projects.automation.deployments.start(
project = api.projectIdentifier(),
targetIdentifier = TargetIdentifier.Key("gradle-tools"),
version = version,
// automatically update deployment status based on a status of a job
syncWithAutomationJob = true
)
try {
api.gradlew(
"publishAllPublicationsToSpaceRepository",
"-Ppublishing.space.user=\"$spaceUser\"",
"-Ppublishing.space.token=\"$spaceToken\"",
)
} catch (ex: Exception) {
println("Publish failed")
}
}
}
}

View File

@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Changed
- Kotlin 2.1.0
- Publication to central via `com.vanniktech.maven.publish.base`
### Deprecated

View File

@ -1,15 +1,14 @@
plugins {
`java-gradle-plugin`
`kotlin-dsl`
`maven-publish`
// signing
`version-catalog`
alias(libs.plugins.maven.publish)
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.jetbrains.dokka)
alias(libs.plugins.versions)
alias(libs.plugins.versions.update)
alias(libs.plugins.maven.publish.base)
}
group = "space.kscience"
@ -26,12 +25,13 @@ repositories {
}
dependencies {
api(libs.kotlin.gradle)
api(libs.foojay.resolver)
implementation(libs.binary.compatibility.validator)
implementation(libs.changelog.gradle)
implementation(libs.dokka.gradle)
implementation(libs.kotlin.jupyter.gradle)
api("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin.asProvider().get()}")
api("org.gradle.toolchains:foojay-resolver:0.9.0")
implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.15.0-Beta.3")
implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:${libs.versions.changelog.get()}")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${libs.versions.dokka.get()}")
implementation("org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin:${libs.versions.kotlin.jupyter.get()}")
implementation("com.vanniktech:gradle-maven-publish-plugin:0.30.0")
implementation(libs.kotlin.serialization)
implementation(libs.kotlinx.html)
implementation(libs.tomlj)
@ -89,30 +89,6 @@ catalog.versionCatalog {
}
//publishing the artifact
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.named("main").get().allSource)
}
val javadocsJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}
val emptyJavadocJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveBaseName.set("empty")
archiveClassifier.set("javadoc")
}
val emptySourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
archiveBaseName.set("empty")
}
mavenPublishing {
configure(
com.vanniktech.maven.publish.GradlePlugin(
@ -121,8 +97,13 @@ mavenPublishing {
)
)
project.publishing.publications.create("maven", MavenPublication::class.java) {
from(project.components.getByName("versionCatalog"))
publishing.publications.create<MavenPublication>("version-catalog") {
from(components["versionCatalog"])
artifactId = "version-catalog"
pom {
name.set("version-catalog")
}
}
val vcs = "https://git.sciprog.center/kscience/gradle-tools"

View File

@ -2,7 +2,7 @@
# @pin
kotlin = "2.1.0"
# @pin
tools = "0.15.8-kotlin-2.1.0"
tools = "0.16.0-kotlin-2.1.0"
atomicfu = "0.26.1"
changelog = "2.2.1"
compose = "1.7.1"
@ -28,9 +28,10 @@ yamlkt = "0.13.0"
[plugins]
maven-publish = { id = "com.vanniktech.maven.publish", version = "0.30.0" }
maven-publish-base = { id = "com.vanniktech.maven.publish.base", version = "0.30.0" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
compose-jb = { id = "org.jetbrains.compose", version.ref = "compose" }
jetbrains-changelog = "org.jetbrains.changelog:2.2.1"
jetbrains-changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
jetbrains-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-android-extensions = { id = "org.jetbrains.kotlin.android.extensions", version.ref = "kotlin" }
@ -60,21 +61,8 @@ versions-update = "nl.littlerobots.version-catalog-update:0.8.5"
[libraries]
atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" }
atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" }
binary-compatibility-validator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.15.0-Beta.3"
changelog-gradle = { module = "org.jetbrains.intellij.plugins:gradle-changelog-plugin", version.ref = "changelog" }
dokka-base = { module = "org.jetbrains.dokka:dokka-base", version.ref = "dokka" }
dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
foojay-resolver = "org.gradle.toolchains:foojay-resolver:0.9.0"
freemarker = "org.freemarker:freemarker:2.3.33"
gradle-changelog-plugin = { module = "org.jetbrains.intellij.plugins:gradle-changelog-plugin", version.ref = "changelog" }
kotlin-assignment-compiler-plugin-embeddable = { module = "org.jetbrains.kotlin:kotlin-assignment-compiler-plugin-embeddable", version.ref = "kotlin" }
kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-js-wrappers = { module = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom", version.ref = "jsBom" }
kotlin-jupyter-api-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin", version.ref = "kotlin" }
kotlin-jupyter-gradle = { module = "org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin", version.ref = "kotlin-jupyter" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-sam-with-receiver-compiler-plugin-embeddable = { module = "org.jetbrains.kotlin:kotlin-sam-with-receiver-compiler-plugin-embeddable", version.ref = "kotlin" }
kotlin-scripting-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable", version.ref = "kotlin" }

View File

@ -1,5 +1,7 @@
package space.kscience.gradle
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.MavenPublishBasePlugin
import kotlinx.validation.ApiValidationExtension
import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin
@ -16,7 +18,6 @@ import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import space.kscience.gradle.internal.addPublishing
import space.kscience.gradle.internal.addSonatypePublishing
import space.kscience.gradle.internal.setupPublication
/**
@ -69,11 +70,32 @@ public class KSciencePublishingExtension(public val project: Project) {
/**
* Adds Sonatype Maven repository to publishing.
*/
public fun sonatype(sonatypeRoot: String = "https://s01.oss.sonatype.org") {
public fun sonatype(sonatypeRoot: String = "https://s01.oss.sonatype.org"): Unit = with(project) {
require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
project.addSonatypePublishing(sonatypeRoot)
if (isInDevelopment) {
logger.info("Sonatype publishing skipped for development version")
} else {
addPublishing("sonatype", "$sonatypeRoot/service/local/staging/deploy/maven2")
}
}
/**
* Add publishing to maven central "new" API
*/
public fun central(): Unit = with(project) {
require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
if (isInDevelopment) {
logger.info("Maven central publishing skipped for development version")
} else {
allprojects {
plugins.withType<MavenPublishBasePlugin> {
extensions.configure<MavenPublishBaseExtension> {
publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.CENTRAL_PORTAL)
}
}
}
}
}
}
@ -87,6 +109,9 @@ public open class KScienceProjectPlugin : Plugin<Project> {
apply<DokkaPlugin>()
apply<BinaryCompatibilityValidatorPlugin>()
val ksciencePublish = KSciencePublishingExtension(this)
extensions.add("ksciencePublish", ksciencePublish)
allprojects {
repositories {
mavenCentral()
@ -113,8 +138,6 @@ public open class KScienceProjectPlugin : Plugin<Project> {
}
val rootReadmeExtension = KScienceReadmeExtension(this)
val ksciencePublish = KSciencePublishingExtension(this)
extensions.add("ksciencePublish", ksciencePublish)
extensions.add("readme", rootReadmeExtension)
//Add readme generators to individual subprojects

View File

@ -1,15 +1,14 @@
package space.kscience.gradle.internal
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.MavenPublishBasePlugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.gradle.plugins.signing.SigningPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import space.kscience.gradle.isInDevelopment
internal fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String
?: System.getenv(propertyName)
@ -20,6 +19,8 @@ internal fun Project.requestProperty(propertyName: String): String = requestProp
internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit = {}) = allprojects {
plugins.withId("maven-publish") {
apply<MavenPublishBasePlugin>()
configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.jvm") {
@ -64,22 +65,12 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
}
}
if (requestPropertyOrNull("publishing.signing.id") != null || requestPropertyOrNull("signing.gnupg.keyName") != null) {
if (!plugins.hasPlugin("signing")) {
apply<SigningPlugin>()
}
extensions.configure<SigningExtension>("signing") {
val signingId: String? = requestPropertyOrNull("publishing.signing.id")
if (!signingId.isNullOrBlank()) {
val signingKey: String = requestProperty("publishing.signing.key")
val signingPassphrase: String = requestProperty("publishing.signing.passPhrase")
// if a key is provided, use it
useInMemoryPgpKeys(signingId, signingKey, signingPassphrase)
} // else use agent signing
sign(publications)
//apply signing if signing configuration is available
if (requestPropertyOrNull("signing.password") != null || requestPropertyOrNull("signing.secretKeyRingFile") != null) {
plugins.withType<MavenPublishBasePlugin> {
extensions.configure<MavenPublishBaseExtension> {
signAllPublications()
}
}
} else {
logger.warn("Signing information is not provided. Skipping artefact signing.")
@ -90,9 +81,9 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
internal fun Project.addPublishing(
repositoryName: String,
urlString:String
){
require(repositoryName.matches("\\w*".toRegex())){"Repository name must contain only letters or numbers"}
urlString: String
) {
require(repositoryName.matches("\\w*".toRegex())) { "Repository name must contain only letters or numbers" }
val user: String? = requestPropertyOrNull("publishing.$repositoryName.user")
val token: String? = requestPropertyOrNull("publishing.$repositoryName.token")
@ -119,12 +110,3 @@ internal fun Project.addPublishing(
}
}
}
internal fun Project.addSonatypePublishing(sonatypeRoot: String) {
if (isInDevelopment) {
logger.info("Sonatype publishing skipped for development version")
} else {
addPublishing("sonatype", "$sonatypeRoot/service/local/staging/deploy/maven2")
}
}