Skip to content

Commit 2015b2f

Browse files
committed
Migrate to io.github.gradle-nexus:publish-plugin
1 parent 87109ac commit 2015b2f

File tree

3 files changed

+80
-121
lines changed

3 files changed

+80
-121
lines changed

checksum.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<dependency group='gradle.plugin.org.jetbrains.gradle.plugin.idea-ext' module='gradle-idea-ext' version='0.7'>
7777
<sha512>A85249BA2BB5713B3779B88F3593CA60EA8739860327DAACE205057F811BAA330E772E4DD4B7BC42BBBFA589ACE38210AAFB0CF2919F5691794E6D9C5C505DAD</sha512>
7878
</dependency>
79+
<dependency group='io.github.gradle-nexus' module='publish-plugin' version='0.1.0-SNAPSHOT'>
80+
<sha512>A23044E25918FC08882627DB5C3BCEE3E19F2876952C6D0A08848AA1269DA4DB293326441901661B217AC227814B463A1C1660ABC11026A08ECD45938D6DF775</sha512>
81+
</dependency>
7982
<dependency group='net.sf.ezmorph' module='ezmorph' version='1.0.6'>
8083
<sha512>16D30BE564723B74F312B4E7D06F349370FB6726B3162778C869CD723ECA2A40C4972C2757B3E107E1820CEC0D70B0BD2B96EFCD466518FC64495F7AEF97967A</sha512>
8184
</dependency>

plugins/stage-vote-release-plugin/build.gradle.kts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ dependencies {
2222
implementation("org.eclipse.jgit:org.eclipse.jgit:5.6.1.202002131546-r")
2323
implementation("org.ajoberstar.grgit:grgit-gradle:4.0.1")
2424
implementation("org.ajoberstar.grgit:grgit-core:4.0.1")
25-
implementation("de.marcphilipp.gradle:nexus-publish-plugin:0.4.0")
26-
implementation("io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.2")
25+
implementation("io.github.gradle-nexus:publish-plugin:0.1.0-SNAPSHOT")
26+
}
27+
28+
repositories {
29+
maven("https://oss.sonatype.org/content/repositories/snapshots/") {
30+
mavenContent {
31+
snapshotsOnly()
32+
}
33+
}
2734
}

plugins/stage-vote-release-plugin/src/main/kotlin/com/github/vlsi/gradle/release/StageVoteReleasePlugin.kt

Lines changed: 68 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import com.github.vlsi.gradle.properties.dsl.props
2020
import com.github.vlsi.gradle.release.svn.LsDepth
2121
import com.github.vlsi.gradle.release.svn.Svn
2222
import com.github.vlsi.gradle.release.svn.SvnEntry
23-
import de.marcphilipp.gradle.nexus.InitializeNexusStagingRepository
24-
import de.marcphilipp.gradle.nexus.NexusPublishExtension
25-
import io.codearte.gradle.nexus.NexusStagingExtension
26-
import io.codearte.gradle.nexus.NexusStagingPlugin
23+
import io.github.gradlenexus.publishplugin.CloseNexusStagingRepository
24+
import io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository
25+
import io.github.gradlenexus.publishplugin.NexusPublishExtension
26+
import io.github.gradlenexus.publishplugin.ReleaseNexusStagingRepository
2727
import org.ajoberstar.grgit.Grgit
2828
import org.eclipse.jgit.lib.Constants
2929
import org.eclipse.jgit.lib.ObjectId
@@ -48,6 +48,7 @@ import org.gradle.kotlin.dsl.configure
4848
import org.gradle.kotlin.dsl.create
4949
import org.gradle.kotlin.dsl.get
5050
import org.gradle.kotlin.dsl.invoke
51+
import org.gradle.kotlin.dsl.named
5152
import org.gradle.kotlin.dsl.provideDelegate
5253
import org.gradle.kotlin.dsl.register
5354
import org.gradle.kotlin.dsl.the
@@ -58,6 +59,7 @@ import org.gradle.plugins.signing.SigningPlugin
5859
import java.io.File
5960
import java.net.URI
6061
import java.nio.charset.StandardCharsets
62+
import java.time.Duration
6163
import javax.inject.Inject
6264

6365
class StageVoteReleasePlugin @Inject constructor(private val instantiator: Instantiator) :
@@ -122,8 +124,7 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
122124

123125
private fun Project.configureRoot() {
124126
apply(plugin = "org.ajoberstar.grgit")
125-
apply(plugin = "io.codearte.nexus-staging")
126-
apply(plugin = "de.marcphilipp.nexus-publish")
127+
apply(plugin = "io.github.gradle-nexus.publish-plugin")
127128

128129
val releaseFilesConfiguration = configurations[RELEASE_FILES_CONFIGURATION_NAME]
129130
val releaseSignaturesConfiguration = configurations[RELEASE_SIGNATURES_CONFIGURATION_NAME]
@@ -141,16 +142,14 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
141142
val validateRcIndexSpecified = tasks.register(VALIDATE_RC_INDEX_SPECIFIED_TASK_NAME)
142143
val validateBeforeBuildingReleaseArtifacts = tasks.register(VALIDATE_BEFORE_ARTIFACT_BUILD_TASK_NAME)
143144

144-
configureNexusPublish(validateNexusCredentials, validateBeforeBuildingReleaseArtifacts)
145-
146-
configureNexusStaging(releaseExt)
145+
configureNexusPublish(releaseExt, validateNexusCredentials, validateBeforeBuildingReleaseArtifacts)
147146

148147
tasks.named("init").hide()
149148
hideMavenPublishTasks()
150149

151150
// Tasks from NexusStagingPlugin
152-
val closeRepository = tasks.named("closeRepository")
153-
val releaseRepository = tasks.named("releaseRepository")
151+
val closeRepository = tasks.named("close${REPOSITORY_NAME.capitalize()}StagingRepository")
152+
val releaseRepository = tasks.named("release${REPOSITORY_NAME.capitalize()}StagingRepository")
154153

155154
val pushRcTag = createPushRcTag(releaseExt, validateRcIndexSpecified, validateBeforeBuildingReleaseArtifacts, closeRepository)
156155
val pushReleaseTag = createPushReleaseTag(releaseExt, validateRcIndexSpecified, releaseRepository)
@@ -185,8 +184,11 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
185184
}
186185
closeRepository.hide()
187186
releaseRepository.hide()
188-
tasks.named("closeAndReleaseRepository").hide()
189-
tasks.named("getStagingProfile").hide()
187+
// https://github.com/gradle-nexus/publish-plugin/issues/51
188+
afterEvaluate {
189+
tasks.named("closeAndReleaseStagingRepository").hide()
190+
}
191+
tasks.named("closeAndRelease${REPOSITORY_NAME.capitalize()}StagingRepository").hide()
190192

191193
releaseRepository {
192194
// Note: publishSvnDist might fail, and it is easier to rollback than "rollback Nexus"
@@ -195,15 +197,6 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
195197
dependsOn(validateNexusCredentials)
196198
}
197199

198-
// closeRepository does not wait all publications by default, so we add that dependency
199-
allprojects {
200-
plugins.withType<PublishingPlugin> {
201-
closeRepository.configure {
202-
dependsOn(tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME))
203-
}
204-
}
205-
}
206-
207200
pushRcTag {
208201
mustRunAfter(stageSvnDist)
209202
mustRunAfter(closeRepository)
@@ -218,12 +211,26 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
218211
dependsOn(closeRepository)
219212
}
220213

221-
tasks.register(REMOVE_STALE_ARTIFACTS_TASK_NAME, RemoveStaleArtifactsTask::class) {
214+
// Make sure stageDist depends on all the relevant publish tasks
215+
allprojects {
216+
plugins.withType<MavenPublishPlugin> {
217+
stageDist {
218+
dependsOn(tasks.named("publishAllPublicationsTo${REPOSITORY_NAME.capitalize()}Repository"))
219+
}
220+
}
221+
}
222+
223+
val removeStaleArtifacts = tasks.register(REMOVE_STALE_ARTIFACTS_TASK_NAME, RemoveStaleArtifactsTask::class) {
222224
description = "Removes stale artifacts from dist.apache.org (dry run with -PasfDryRun)"
223225
group = RELEASE_GROUP
224226
onlyIf { releaseExt.svnDistEnabled.get() }
225227
mustRunAfter(publishSvnDist)
226228
}
229+
afterEvaluate {
230+
if (!releaseExt.svnDistEnabled.get()) {
231+
removeStaleArtifacts.hide()
232+
}
233+
}
227234

228235
pushReleaseTag {
229236
mustRunAfter(publishSvnDist)
@@ -369,11 +376,15 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
369376

370377
private fun Project.hideMavenPublishTasks() {
371378
allprojects {
379+
plugins.withType<PublishingPlugin> {
380+
tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).hide()
381+
}
372382
plugins.withType<MavenPublishPlugin> {
373383
afterEvaluate {
374384
tasks.withType<PublishToMavenRepository>().hide()
375385
tasks.withType<PublishToMavenLocal>().hide()
376386
tasks.withType<GenerateModuleMetadata>().hide()
387+
tasks.named("publishAllPublicationsTo${REPOSITORY_NAME.capitalize()}Repository").hide()
377388
val generatePomTasks = tasks.withType<GenerateMavenPom>()
378389
generatePomTasks.hide()
379390
tasks.register("generatePom") {
@@ -511,44 +522,6 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
511522
return pushPreviewSite
512523
}
513524

514-
private fun Project.configureNexusStaging(releaseExt: ReleaseExtension) {
515-
plugins.withType<NexusStagingPlugin> {
516-
tasks {
517-
// Hide "deprecated" tasks from "./gradlew tasks"
518-
named("closeAndPromoteRepository").hide()
519-
named("promoteRepository").hide()
520-
// Hide "internal" tasks
521-
named("createRepository").hide()
522-
}
523-
}
524-
// The fields of releaseExt are not configured yet (the extension is not yet used in build scripts),
525-
// so we populate NexusStaging properties after the project is configured
526-
afterEvaluate {
527-
configure<NexusStagingExtension> {
528-
val nexus = project.the<ReleaseExtension>().nexus
529-
packageGroup = nexus.packageGroup.get()
530-
username = nexus.credentials.username(project)
531-
password = nexus.credentials.password(project)
532-
stagingProfileId = nexus.stagingProfileId.orNull
533-
delayBetweenRetriesInMillis = 2000
534-
numberOfRetries = (releaseExt.nexus.operationTimeout.get().toMillis() / 2000).toInt()
535-
if (releaseExt.release.get()) {
536-
repositoryDescription =
537-
"Release ${releaseExt.componentName.get()} ${releaseExt.releaseTag.get()} (${releaseExt.rcTag.orNull ?: ""})"
538-
}
539-
val nexusPublish = project.the<NexusPublishExtension>()
540-
val repo = nexusPublish.repositories[REPOSITORY_NAME]
541-
serverUrl =
542-
repo.run { if (nexusPublish.useStaging.get()) nexusUrl else snapshotRepositoryUrl }
543-
.get().toString()
544-
545-
stagingRepositoryId.set(
546-
project.provider { releaseExt.repositoryIdStore.getOrLoad(REPOSITORY_NAME) }
547-
)
548-
}
549-
}
550-
}
551-
552525
private fun URI.replacePath(path: String) = URI(
553526
scheme,
554527
userInfo,
@@ -560,70 +533,46 @@ class StageVoteReleasePlugin @Inject constructor(private val instantiator: Insta
560533
)
561534

562535
private fun Project.configureNexusPublish(
536+
releaseExt: ReleaseExtension,
563537
validateNexusCredentials: TaskProvider<*>,
564538
validateBeforeBuildingReleaseArtifacts: TaskProvider<*>
565539
) {
566-
val releaseExt = project.the<ReleaseExtension>()
567-
val nexusPublish = the<NexusPublishExtension>()
568-
val repo = nexusPublish.repositories.create(REPOSITORY_NAME) {
569-
nexusUrl.set(releaseExt.nexus.url.map { it.replacePath("/service/local/") })
570-
snapshotRepositoryUrl.set(releaseExt.nexus.url.map { it.replacePath("/content/repositories/snapshots/") })
571-
username.set(project.provider { releaseExt.nexus.credentials.username(project) })
572-
password.set(project.provider { releaseExt.nexus.credentials.password(project) })
573-
}
574-
575-
nexusPublish.connectTimeout.set(releaseExt.nexus.connectTimeout)
576-
nexusPublish.clientTimeout.set(releaseExt.nexus.operationTimeout)
577-
578-
val rootInitStagingRepository = tasks.named("initialize${repo.name.capitalize()}StagingRepository")
579-
// Use the same settings for all subprojects that apply MavenPublishPlugin
580-
subprojects {
581-
plugins.withType<MavenPublishPlugin> {
582-
apply(plugin = "de.marcphilipp.nexus-publish")
583-
584-
configure<NexusPublishExtension> {
585-
connectTimeout.set(nexusPublish.connectTimeout)
586-
clientTimeout.set(nexusPublish.clientTimeout)
587-
repositories.create(repo.name) {
588-
nexusUrl.set(repo.nexusUrl)
589-
snapshotRepositoryUrl.set(repo.snapshotRepositoryUrl)
590-
username.set(repo.username)
591-
password.set(repo.password)
592-
}
593-
useStaging.set(nexusPublish.useStaging)
594-
}
540+
configure<NexusPublishExtension> {
541+
val repo = repositories.create(REPOSITORY_NAME) {
542+
nexusUrl.set(releaseExt.nexus.url.map { it.replacePath("/service/local/") })
543+
snapshotRepositoryUrl.set(releaseExt.nexus.url.map { it.replacePath("/content/repositories/snapshots/") })
544+
username.set(project.provider { releaseExt.nexus.credentials.username(project) })
545+
password.set(project.provider { releaseExt.nexus.credentials.password(project) })
595546
}
596-
plugins.withId("de.marcphilipp.nexus-publish") {
597-
tasks.withType<InitializeNexusStagingRepository>().configureEach {
598-
// Allow for some parallelism, so the staging repository is created by the root task
599-
dependsOn(rootInitStagingRepository)
600-
}
547+
connectTimeout.set(releaseExt.nexus.connectTimeout)
548+
clientTimeout.set(releaseExt.nexus.operationTimeout)
549+
val nexus = releaseExt.nexus
550+
packageGroup.set(nexus.packageGroup)
551+
transitionCheckOptions {
552+
delayBetween.set(Duration.ofSeconds(10))
553+
maxRetries.set(nexus.operationTimeout.map { (1 + it.toSeconds() / 10).toInt() })
601554
}
602-
}
603-
604-
// We don't know which project will be the first to initialize the staging repository,
605-
// so we watch all the projects
606-
// The goal of this block is to fetch and save the Id of newly created staging repository
607-
allprojects {
608-
plugins.withId("de.marcphilipp.nexus-publish") {
609-
// Hide unused task: https://github.com/marcphilipp/nexus-publish-plugin/issues/14
610-
configure<NexusPublishExtension> {
611-
repositories.whenObjectAdded {
612-
tasks.named("publishTo${name.capitalize()}") {
613-
group = null
614-
}
615-
}
555+
repositoryDescription.set(project.provider {
556+
if (releaseExt.release.get()) {
557+
project.run { "$group:$name:$version" }
558+
} else {
559+
"Release ${releaseExt.componentName.get()} ${releaseExt.releaseTag.get()} (${releaseExt.rcTag.orNull ?: ""})"
616560
}
617-
tasks.withType<InitializeNexusStagingRepository>().configureEach {
618-
dependsOn(validateBeforeBuildingReleaseArtifacts)
619-
dependsOn(validateNexusCredentials)
620-
doLast {
621-
// nexus-publish puts stagingRepositoryId to NexusStagingExtension so we get it from there
622-
val repoName = this@configureEach.repositoryName.get()
623-
val stagingRepositoryId =
624-
rootProject.the<NexusStagingExtension>().stagingRepositoryId.get()
625-
releaseExt.repositoryIdStore[repoName] = stagingRepositoryId
626-
}
561+
})
562+
563+
tasks.named<ReleaseNexusStagingRepository>("release${REPOSITORY_NAME.capitalize()}StagingRepository") {
564+
stagingRepositoryId.set(project.provider { releaseExt.repositoryIdStore.getOrLoad(REPOSITORY_NAME) })
565+
}
566+
tasks.named<InitializeNexusStagingRepository>("initialize${repo.name.capitalize()}StagingRepository") {
567+
dependsOn(validateBeforeBuildingReleaseArtifacts)
568+
dependsOn(validateNexusCredentials)
569+
doLast {
570+
val repoName = repository.get().name
571+
val closeRepoTask =
572+
rootProject.tasks.named<CloseNexusStagingRepository>("close${repoName.capitalize()}StagingRepository")
573+
val stagingRepositoryId =
574+
closeRepoTask.get().stagingRepositoryId.get()
575+
releaseExt.repositoryIdStore[repoName] = stagingRepositoryId
627576
}
628577
}
629578
}

0 commit comments

Comments
 (0)