From ffc5b030f91745073b29ddfdc884313628bb3b5c Mon Sep 17 00:00:00 2001 From: Ilya Muradyan Date: Tue, 16 Feb 2021 14:13:43 +0300 Subject: [PATCH] Publish with nexus-publish-plugin --- build.gradle.kts | 8 ++------ .../jupyter/api/plugin/ApiGradlePlugin.kt | 1 - .../jupyter/plugin/ApiPublishGradlePlugin.kt | 2 ++ .../kotlinx/jupyter/publishing/nexusUtil.kt | 17 ++++++++++++++++- .../kotlinx/jupyter/publishing/publication.kt | 16 +++------------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 28afb3f6f..4c7fb0bde 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -115,18 +115,14 @@ tasks.register("publishLocal") { ) } -val publishToSonatype by tasks.registering { - group = "publishing" -} - tasks.named("closeRepository") { - mustRunAfter(publishToSonatype) + mustRunAfter("publishToSonatype") } tasks.register("publishToSonatypeAndRelease") { group = "publishing" - dependsOn(publishToSonatype, "closeAndReleaseRepository") + dependsOn("publishToSonatype", "closeAndReleaseRepository") } tasks.register("publishToPluginPortal") { diff --git a/jupyter-lib/api-gradle-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/plugin/ApiGradlePlugin.kt b/jupyter-lib/api-gradle-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/plugin/ApiGradlePlugin.kt index 457f46c1e..658a855da 100644 --- a/jupyter-lib/api-gradle-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/plugin/ApiGradlePlugin.kt +++ b/jupyter-lib/api-gradle-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/plugin/ApiGradlePlugin.kt @@ -3,7 +3,6 @@ package org.jetbrains.kotlinx.jupyter.api.plugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.invoke -import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.repositories import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin diff --git a/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/plugin/ApiPublishGradlePlugin.kt b/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/plugin/ApiPublishGradlePlugin.kt index bb2fe9425..a1f89237c 100644 --- a/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/plugin/ApiPublishGradlePlugin.kt +++ b/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/plugin/ApiPublishGradlePlugin.kt @@ -1,5 +1,6 @@ package org.jetbrains.kotlinx.jupyter.plugin +import de.marcphilipp.gradle.nexus.NexusPublishPlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.publish.maven.plugins.MavenPublishPlugin @@ -11,6 +12,7 @@ class ApiPublishGradlePlugin : Plugin { target.pluginManager.run { apply(DokkaPlugin::class.java) apply(MavenPublishPlugin::class.java) + apply(NexusPublishPlugin::class.java) apply(SigningPlugin::class.java) } } diff --git a/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/nexusUtil.kt b/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/nexusUtil.kt index 941ac419d..da57d90a3 100644 --- a/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/nexusUtil.kt +++ b/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/nexusUtil.kt @@ -1,5 +1,7 @@ package org.jetbrains.kotlinx.jupyter.publishing +import de.marcphilipp.gradle.nexus.NexusPublishExtension +import de.marcphilipp.gradle.nexus.NexusPublishPlugin import io.codearte.gradle.nexus.NexusStagingExtension import io.codearte.gradle.nexus.NexusStagingPlugin import org.gradle.api.Project @@ -15,9 +17,21 @@ fun getNexusPassword(): String? { return System.getenv("SONATYPE_PASSWORD") } +fun Project.configureNexusPublish() { + extensions.configure("nexusPublishing") { + repositories { + sonatype { + username.set(getNexusUser()) + password.set(getNexusPassword()) + } + } + } +} + fun Project.applyNexusPlugin() { pluginManager.run { apply(NexusStagingPlugin::class.java) + apply(NexusPublishPlugin::class.java) } extensions.configure("nexusStaging") { @@ -25,6 +39,7 @@ fun Project.applyNexusPlugin() { password = getNexusPassword() packageGroup = NEXUS_PACKAGE_GROUP repositoryDescription = "kotlin-jupyter project, v. ${project.version}" - // serverUrl = NEXUS_REPO_URL } + + configureNexusPublish() } \ No newline at end of file diff --git a/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/publication.kt b/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/publication.kt index e5d186f28..bec028a65 100644 --- a/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/publication.kt +++ b/kotlin-jupyter-publish/src/main/kotlin/org/jetbrains/kotlinx/jupyter/publishing/publication.kt @@ -11,7 +11,6 @@ import org.gradle.kotlin.dsl.invoke import org.gradle.plugins.signing.SigningExtension import org.jetbrains.dokka.gradle.DokkaTask import java.io.File -import java.net.URI import java.nio.file.Path fun Project.addPublication(configuration: ArtifactPublication.() -> Unit) { @@ -21,8 +20,6 @@ fun Project.addPublication(configuration: ArtifactPublication.() -> Unit) { val mainSourceSet = sourceSets.named("main").get() val publicationName = settings.publicationName!! - val sonatypeUser = getNexusUser() - val sonatypePassword = getNexusPassword() val signingPrivateKey = System.getenv("SIGN_KEY_PRIVATE") val signingKey = System.getenv("SIGN_KEY_ID") val signingKeyPassphrase = System.getenv("SIGN_KEY_PASSPHRASE") @@ -108,19 +105,11 @@ fun Project.addPublication(configuration: ArtifactPublication.() -> Unit) { url = it.toUri() } } - - maven { - name = "Sonatype" - url = URI(NEXUS_REPO_URL) - credentials { - username = sonatypeUser - password = sonatypePassword - } - } } } val thisProjectName = project.name + val thisProject = project if (rootProject.findProperty("isMainProject") == true) { rootProject.tasks { @@ -129,8 +118,9 @@ fun Project.addPublication(configuration: ArtifactPublication.() -> Unit) { } if (settings.publishToSonatype) { + thisProject.configureNexusPublish() named("publishToSonatype") { - dependsOn(":$thisProjectName:publishAllPublicationsToSonatypeRepository") + dependsOn(":$thisProjectName:publishToSonatype") } } }