Fix publishing for gradle 8

This commit is contained in:
Alexander Nozik 2023-03-12 12:15:20 +03:00
parent d0079ba307
commit e535fdc6f5
5 changed files with 117 additions and 100 deletions

View File

@ -104,107 +104,116 @@ val javadocsJar by tasks.creating(Jar::class) {
from(tasks.dokkaHtml) from(tasks.dokkaHtml)
} }
afterEvaluate { val emptyJavadocJar by tasks.creating(Jar::class) {
publishing { group = JavaBasePlugin.DOCUMENTATION_GROUP
val vcs = "https://github.com/mipt-npm/gradle-tools" archiveBaseName.set("empty")
archiveClassifier.set("javadoc")
}
// Process each publication we have in this project
publications {
create<MavenPublication>("catalog") {
from(components["versionCatalog"])
artifactId = "version-catalog"
pom { val emptySourcesJar by tasks.creating(Jar::class) {
name.set("version-catalog") archiveClassifier.set("sources")
} archiveBaseName.set("empty")
}
publishing {
val vcs = "https://github.com/mipt-npm/gradle-tools"
// Process each publication we have in this project
publications {
create<MavenPublication>("catalog") {
from(components["versionCatalog"])
artifactId = "version-catalog"
pom {
name.set("version-catalog")
} }
}
withType<MavenPublication> { withType<MavenPublication> {
artifact(sourcesJar) // thanks @vladimirsitnikv for the fix
artifact(javadocsJar) artifact(if (name == "catalog") emptySourcesJar else sourcesJar)
artifact(if (name == "catalog") emptyJavadocJar else javadocsJar)
pom {
name.set(project.name) pom {
description.set(project.description) name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("https://npm.mipt.ru")
}
}
scm {
url.set(vcs) url.set(vcs)
tag.set(project.version.toString())
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("https://npm.mipt.ru")
}
}
scm {
url.set(vcs)
tag.set(project.version.toString())
}
} }
} }
} }
}
val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven" val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven"
val spaceUser: String? = findProperty("publishing.space.user") as? String val spaceUser: String? = findProperty("publishing.space.user") as? String
val spaceToken: String? = findProperty("publishing.space.token") as? String val spaceToken: String? = findProperty("publishing.space.token") as? String
if (spaceUser != null && spaceToken != null) { if (spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories.maven { repositories.maven {
name = "space" name = "space"
url = uri(spaceRepo) url = uri(spaceRepo)
credentials { credentials {
username = spaceUser username = spaceUser
password = spaceToken password = spaceToken
} }
}
}
val sonatypeUser: String? = project.findProperty("publishing.sonatype.user") as? String
val sonatypePassword: String? = project.findProperty("publishing.sonatype.password") as? String
if (sonatypeUser != null && sonatypePassword != null) {
val sonatypeRepo: String = if (project.version.toString().contains("dev")) {
"https://oss.sonatype.org/content/repositories/snapshots"
} else {
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
}
repositories.maven {
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
} }
} }
val sonatypeUser: String? = project.findProperty("publishing.sonatype.user") as? String signing {
val sonatypePassword: String? = project.findProperty("publishing.sonatype.password") as? String //useGpgCmd()
sign(publications)
if (sonatypeUser != null && sonatypePassword != null) {
val sonatypeRepo: String = if (project.version.toString().contains("dev")) {
"https://oss.sonatype.org/content/repositories/snapshots"
} else {
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
}
repositories.maven {
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
}
if (plugins.findPlugin("signing") == null) {
apply<SigningPlugin>()
}
signing {
//useGpgCmd()
sign(publications)
}
} }
} }
} }
kotlin{
jvmToolchain{ kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11)) languageVersion.set(JavaLanguageVersion.of(11))
} }
} }
@ -213,3 +222,8 @@ tasks.processResources.configure {
duplicatesStrategy = DuplicatesStrategy.INCLUDE duplicatesStrategy = DuplicatesStrategy.INCLUDE
from("gradle/libs.versions.toml") from("gradle/libs.versions.toml")
} }
// Workaround for https://github.com/gradle/gradle/issues/15568
tasks.withType<AbstractPublishToMaven>().configureEach {
mustRunAfter(tasks.withType<Sign>())
}

View File

@ -1,11 +1,11 @@
[versions] [versions]
tools = "0.14.3-kotlin-1.8.10" tools = "0.14.4-kotlin-1.8.20-RC"
kotlin = "1.8.10" kotlin = "1.8.20-RC"
atomicfu = "0.19.0" atomicfu = "0.19.0"
binary-compatibility-validator = "0.12.1" binary-compatibility-validator = "0.12.1"
changelog = "2.0.0" changelog = "2.0.0"
dokka = "1.7.20" dokka = "1.7.20"
kotlin-jupyter = "0.11.0-225" kotlin-jupyter = "0.11.0-317"
kotlinx-benchmark = "0.4.7" kotlinx-benchmark = "0.4.7"
kotlinx-cli = "0.3.5" kotlinx-cli = "0.3.5"
kotlinx-coroutines = "1.6.4" kotlinx-coroutines = "1.6.4"
@ -17,7 +17,7 @@ kotlinx-serialization = "1.4.1"
ktor = "2.2.3" ktor = "2.2.3"
xmlutil = "0.84.3" xmlutil = "0.84.3"
yamlkt = "0.12.0" yamlkt = "0.12.0"
jsBom = "1.0.0-pre.491" jsBom = "1.0.0-pre.509"
junit = "5.9.2" junit = "5.9.2"
compose = "1.3.0" compose = "1.3.0"
logback = "1.4.5" logback = "1.4.5"

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -5,7 +5,9 @@ import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.Sign
import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.changelog.ChangelogPluginExtension import org.jetbrains.changelog.ChangelogPluginExtension
import org.jetbrains.dokka.gradle.AbstractDokkaTask import org.jetbrains.dokka.gradle.AbstractDokkaTask
@ -108,6 +110,11 @@ public open class KScienceProjectPlugin : Plugin<Project> {
maven("https://repo.kotlin.link") maven("https://repo.kotlin.link")
maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev") maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev")
} }
// Workaround for https://github.com/gradle/gradle/issues/15568
tasks.withType<AbstractPublishToMaven>().configureEach {
mustRunAfter(tasks.withType<Sign>())
}
} }
afterEvaluate { afterEvaluate {

View File

@ -34,14 +34,12 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
} }
} }
afterEvaluate { publications.create<MavenPublication>("js") {
publications.create<MavenPublication>("js") { kotlin.targets.flatMap { it.components }.forEach {
kotlin.targets.flatMap { it.components }.forEach { from(it)
from(it)
}
artifact(sourcesJar)
} }
artifact(sourcesJar)
} }
} }
@ -56,14 +54,12 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
} }
} }
afterEvaluate { publications.create<MavenPublication>("jvm") {
publications.create<MavenPublication>("jvm") { kotlin.target.components.forEach {
kotlin.target.components.forEach { from(it)
from(it)
}
artifact(sourcesJar)
} }
artifact(sourcesJar)
} }
} }