Skip to content

Commit

Permalink
Publish with nexus-publish-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ileasile committed Feb 16, 2021
1 parent 7ac4396 commit ffc5b03
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
8 changes: 2 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,7 @@ class ApiPublishGradlePlugin : Plugin<Project> {
target.pluginManager.run {
apply(DokkaPlugin::class.java)
apply(MavenPublishPlugin::class.java)
apply(NexusPublishPlugin::class.java)
apply(SigningPlugin::class.java)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,16 +17,29 @@ fun getNexusPassword(): String? {
return System.getenv("SONATYPE_PASSWORD")
}

fun Project.configureNexusPublish() {
extensions.configure<NexusPublishExtension>("nexusPublishing") {
repositories {
sonatype {
username.set(getNexusUser())
password.set(getNexusPassword())
}
}
}
}

fun Project.applyNexusPlugin() {
pluginManager.run {
apply(NexusStagingPlugin::class.java)
apply(NexusPublishPlugin::class.java)
}

extensions.configure<NexusStagingExtension>("nexusStaging") {
username = getNexusUser()
password = getNexusPassword()
packageGroup = NEXUS_PACKAGE_GROUP
repositoryDescription = "kotlin-jupyter project, v. ${project.version}"
// serverUrl = NEXUS_REPO_URL
}

configureNexusPublish()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -129,8 +118,9 @@ fun Project.addPublication(configuration: ArtifactPublication.() -> Unit) {
}

if (settings.publishToSonatype) {
thisProject.configureNexusPublish()
named("publishToSonatype") {
dependsOn(":$thisProjectName:publishAllPublicationsToSonatypeRepository")
dependsOn(":$thisProjectName:publishToSonatype")
}
}
}
Expand Down

0 comments on commit ffc5b03

Please sign in to comment.