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)
}
afterEvaluate {
publishing {
val vcs = "https://github.com/mipt-npm/gradle-tools"
val emptyJavadocJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
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 {
name.set("version-catalog")
}
val emptySourcesJar by tasks.creating(Jar::class) {
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> {
artifact(sourcesJar)
artifact(javadocsJar)
withType<MavenPublication> {
// thanks @vladimirsitnikv for the fix
artifact(if (name == "catalog") emptySourcesJar else sourcesJar)
artifact(if (name == "catalog") emptyJavadocJar else javadocsJar)
pom {
name.set(project.name)
description.set(project.description)
pom {
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)
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())
}
tag.set(project.version.toString())
}
}
}
}
val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven"
val spaceUser: String? = findProperty("publishing.space.user") as? String
val spaceToken: String? = findProperty("publishing.space.token") as? String
val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven"
val spaceUser: String? = findProperty("publishing.space.user") as? String
val spaceToken: String? = findProperty("publishing.space.token") as? String
if (spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
if (spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories.maven {
name = "space"
url = uri(spaceRepo)
repositories.maven {
name = "space"
url = uri(spaceRepo)
credentials {
username = spaceUser
password = spaceToken
}
credentials {
username = spaceUser
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
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
}
}
if (plugins.findPlugin("signing") == null) {
apply<SigningPlugin>()
}
signing {
//useGpgCmd()
sign(publications)
}
signing {
//useGpgCmd()
sign(publications)
}
}
}
kotlin{
jvmToolchain{
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
@ -212,4 +221,9 @@ kotlin{
tasks.processResources.configure {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
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]
tools = "0.14.3-kotlin-1.8.10"
kotlin = "1.8.10"
tools = "0.14.4-kotlin-1.8.20-RC"
kotlin = "1.8.20-RC"
atomicfu = "0.19.0"
binary-compatibility-validator = "0.12.1"
changelog = "2.0.0"
dokka = "1.7.20"
kotlin-jupyter = "0.11.0-225"
kotlin-jupyter = "0.11.0-317"
kotlinx-benchmark = "0.4.7"
kotlinx-cli = "0.3.5"
kotlinx-coroutines = "1.6.4"
@ -17,7 +17,7 @@ kotlinx-serialization = "1.4.1"
ktor = "2.2.3"
xmlutil = "0.84.3"
yamlkt = "0.12.0"
jsBom = "1.0.0-pre.491"
jsBom = "1.0.0-pre.509"
junit = "5.9.2"
compose = "1.3.0"
logback = "1.4.5"

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
zipStorePath=wrapper/dists

View File

@ -5,7 +5,9 @@ import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.Sign
import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.changelog.ChangelogPluginExtension
import org.jetbrains.dokka.gradle.AbstractDokkaTask
@ -108,6 +110,11 @@ public open class KScienceProjectPlugin : Plugin<Project> {
maven("https://repo.kotlin.link")
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 {

View File

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