Skip to content

Commit

Permalink
Use Gradle Nexus Publish Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 committed Feb 26, 2024
1 parent bab1436 commit ca611cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions sonatype/src/main/kotlin/com/bakdata/gradle/SonatypePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class SonatypePlugin : Plugin<Project> {
}

configure<NexusPublishExtension> {
// use default repository called 'sonatype' and set the corresponding default urls
repositories.sonatype {
// create default repository called 'nexus' and set the corresponding default urls
repositories.create("nexus") {
nexusUrl.set(URI.create("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
Expand All @@ -101,7 +101,7 @@ class SonatypePlugin : Plugin<Project> {
project.configure<NexusPublishExtension> {
packageGroup.set("com.bakdata")

repositories.getByName("sonatype").apply {
repositories["nexus"].apply {
stagingProfileId.set("8412378836ed9c")
username.set(getOverriddenSetting(SonatypeSettings::osshrUsername))
password.set(getOverriddenSetting(SonatypeSettings::osshrPassword))
Expand Down Expand Up @@ -136,7 +136,7 @@ class SonatypePlugin : Plugin<Project> {

if (this.allTasks.any { it is AbstractPublishToMaven }) {
project.configure<NexusPublishExtension> {
repositories.getByName("sonatype").apply {
repositories["nexus"].apply {
if (!username.isPresent) {
missingProps.add(SonatypeSettings::osshrUsername)
}
Expand All @@ -150,11 +150,11 @@ class SonatypePlugin : Plugin<Project> {
allprojects {
extensions.findByType<NexusPublishExtension>()?.let { nexus ->
getOverriddenSetting(SonatypeSettings::nexusUrl)?.let {
nexus.repositories.getByName("sonatype").nexusUrl.value(uri(it))
nexus.repositories["nexus"].nexusUrl.value(uri(it))
}

getOverriddenSetting(SonatypeSettings::snapshotUrl)?.let {
nexus.repositories.getByName("sonatype").snapshotRepositoryUrl.value(uri(it))
nexus.repositories["nexus"].snapshotRepositoryUrl.value(uri(it))
}

getOverriddenSetting(SonatypeSettings::clientTimeout)?.let {
Expand Down Expand Up @@ -194,7 +194,7 @@ class SonatypePlugin : Plugin<Project> {
gradle.taskGraph.whenReady {
if (getOverriddenSetting(SonatypeSettings::disallowLocalRelease)!!) {
log.info("disallowing publish tasks")
if (hasTask(":publishToSonatype") && System.getenv("CI") == null) {
if (hasTask(":publishToNexus") && System.getenv("CI") == null) {
throw GradleException("Publishing artifacts is only supported through CI (e.g., Travis)")
}
if (hasTask(":release") && System.getenv("CI") == null) {
Expand Down Expand Up @@ -287,7 +287,7 @@ class SonatypePlugin : Plugin<Project> {
private fun Project.logNexusPublishingSetting() {
extensions.findByType(NexusPublishExtension::class)?.let {
project.logger.debug(
"Publish to Nexus (${it.repositories.getByName("sonatype").nexusUrl.get()}) " +
"Publish to Nexus (${it.repositories["nexus"].nexusUrl.get()}) " +
"with connect timeout of ${it.connectTimeout.get()} " +
"and client timeout of ${it.clientTimeout.get()}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal class SonatypePluginIT {

val result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.withArguments("publishToSonatype", "closeAndReleaseStagingRepository", "--stacktrace", "--info")
.withArguments("publishToNexus", "closeAndReleaseStagingRepository", "--stacktrace", "--info")
.withProjectPluginClassPath()
.build()

Expand Down Expand Up @@ -192,7 +192,7 @@ internal class SonatypePluginIT {

val result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.withArguments("publishToSonatype", "closeAndReleaseStagingRepository", "--stacktrace", "--info")
.withArguments("publishToNexus", "closeAndReleaseStagingRepository", "--stacktrace", "--info")
.withProjectPluginClassPath()
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal class SonatypePluginTest {
softly.assertThat(project.tasks)
.haveExactly(1, taskWithName("signSonatypePublication"))
.haveExactly(1, taskWithName("publish"))
.haveExactly(1, taskWithName("publishToSonatype"))
.haveExactly(1, taskWithName("publishToNexus"))
.haveExactly(1, taskWithName("closeAndReleaseStagingRepository"))
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ internal class SonatypePluginTest {
softly.assertThat(child.tasks)
.haveExactly(1, taskWithName("signSonatypePublication"))
.haveExactly(1, taskWithName("publish"))
.haveExactly(1, taskWithName("publishToSonatype"))
.haveExactly(1, taskWithName("publishToNexus"))
.haveExactly(0, taskWithName("closeAndReleaseStagingRepository"))
}
}
Expand All @@ -102,7 +102,7 @@ internal class SonatypePluginTest {
softly.assertThat(parent.tasks)
.haveExactly(0, taskWithName("signSonatypePublication"))
.haveExactly(0, taskWithName("publish"))
.haveExactly(0, taskWithName("publishToSonatype"))
.haveExactly(0, taskWithName("publishToNexus"))
.haveExactly(1, taskWithName("closeAndReleaseStagingRepository"))
}
}
Expand Down

0 comments on commit ca611cd

Please sign in to comment.