@@ -20,10 +20,10 @@ import com.github.vlsi.gradle.properties.dsl.props
2020import com.github.vlsi.gradle.release.svn.LsDepth
2121import com.github.vlsi.gradle.release.svn.Svn
2222import 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
2727import org.ajoberstar.grgit.Grgit
2828import org.eclipse.jgit.lib.Constants
2929import org.eclipse.jgit.lib.ObjectId
@@ -49,6 +49,7 @@ import org.gradle.kotlin.dsl.configure
4949import org.gradle.kotlin.dsl.create
5050import org.gradle.kotlin.dsl.get
5151import org.gradle.kotlin.dsl.invoke
52+ import org.gradle.kotlin.dsl.named
5253import org.gradle.kotlin.dsl.provideDelegate
5354import org.gradle.kotlin.dsl.register
5455import org.gradle.kotlin.dsl.the
@@ -60,6 +61,7 @@ import org.gradle.process.ExecOperations
6061import java.io.File
6162import java.net.URI
6263import java.nio.charset.StandardCharsets
64+ import java.time.Duration
6365import javax.inject.Inject
6466
6567class StageVoteReleasePlugin @Inject constructor(
@@ -127,8 +129,7 @@ class StageVoteReleasePlugin @Inject constructor(
127129
128130 private fun Project.configureRoot () {
129131 apply (plugin = " org.ajoberstar.grgit" )
130- apply (plugin = " io.codearte.nexus-staging" )
131- apply (plugin = " de.marcphilipp.nexus-publish" )
132+ apply (plugin = " io.github.gradle-nexus.publish-plugin" )
132133
133134 val releaseFilesConfiguration = configurations[RELEASE_FILES_CONFIGURATION_NAME ]
134135 val releaseSignaturesConfiguration = configurations[RELEASE_SIGNATURES_CONFIGURATION_NAME ]
@@ -146,18 +147,16 @@ class StageVoteReleasePlugin @Inject constructor(
146147 val validateRcIndexSpecified = tasks.register(VALIDATE_RC_INDEX_SPECIFIED_TASK_NAME )
147148 val validateBeforeBuildingReleaseArtifacts = tasks.register(VALIDATE_BEFORE_ARTIFACT_BUILD_TASK_NAME )
148149
149- configureNexusPublish(validateNexusCredentials, validateBeforeBuildingReleaseArtifacts)
150-
151- configureNexusStaging(releaseExt)
150+ configureNexusPublish(releaseExt, validateNexusCredentials, validateBeforeBuildingReleaseArtifacts)
152151
153152 plugins.withId(" build-init" ) {
154153 tasks.named(" init" ).hide()
155154 }
156155 hideMavenPublishTasks()
157156
158157 // Tasks from NexusStagingPlugin
159- val closeRepository = tasks.named(" closeRepository " )
160- val releaseRepository = tasks.named(" releaseRepository " )
158+ val closeRepository = tasks.named(" close ${ REPOSITORY_NAME .capitalize()} StagingRepository " )
159+ val releaseRepository = tasks.named(" release ${ REPOSITORY_NAME .capitalize()} StagingRepository " )
161160
162161 val pushRcTag = createPushRcTag(releaseExt, validateRcIndexSpecified, validateBeforeBuildingReleaseArtifacts, closeRepository)
163162 val pushReleaseTag = createPushReleaseTag(releaseExt, validateRcIndexSpecified, releaseRepository)
@@ -205,8 +204,7 @@ class StageVoteReleasePlugin @Inject constructor(
205204 }
206205 closeRepository.hide()
207206 releaseRepository.hide()
208- tasks.named(" closeAndReleaseRepository" ).hide()
209- tasks.named(" getStagingProfile" ).hide()
207+ tasks.named(" closeAndRelease${REPOSITORY_NAME .capitalize()} StagingRepository" ).hide()
210208
211209 releaseRepository {
212210 // Note: publishSvnDist might fail, and it is easier to rollback than "rollback Nexus"
@@ -215,15 +213,6 @@ class StageVoteReleasePlugin @Inject constructor(
215213 dependsOn(validateNexusCredentials)
216214 }
217215
218- // closeRepository does not wait all publications by default, so we add that dependency
219- allprojects {
220- plugins.withType<PublishingPlugin > {
221- closeRepository.configure {
222- dependsOn(tasks.named(PublishingPlugin .PUBLISH_LIFECYCLE_TASK_NAME ))
223- }
224- }
225- }
226-
227216 pushRcTag {
228217 mustRunAfter(stageSvnDist)
229218 mustRunAfter(closeRepository)
@@ -238,12 +227,26 @@ class StageVoteReleasePlugin @Inject constructor(
238227 dependsOn(closeRepository)
239228 }
240229
241- tasks.register(REMOVE_STALE_ARTIFACTS_TASK_NAME , RemoveStaleArtifactsTask ::class ) {
230+ // Make sure stageDist depends on all the relevant publish tasks
231+ allprojects {
232+ plugins.withType<MavenPublishPlugin > {
233+ stageDist {
234+ dependsOn(tasks.named(" publishAllPublicationsTo${REPOSITORY_NAME .capitalize()} Repository" ))
235+ }
236+ }
237+ }
238+
239+ val removeStaleArtifacts = tasks.register(REMOVE_STALE_ARTIFACTS_TASK_NAME , RemoveStaleArtifactsTask ::class ) {
242240 description = " Removes stale artifacts from dist.apache.org (dry run with -PasfDryRun)"
243241 group = RELEASE_GROUP
244242 onlyIf { releaseExt.svnDistEnabled.get() }
245243 mustRunAfter(publishSvnDist)
246244 }
245+ afterEvaluate {
246+ if (! releaseExt.svnDistEnabled.get()) {
247+ removeStaleArtifacts.hide()
248+ }
249+ }
247250
248251 pushReleaseTag {
249252 mustRunAfter(publishSvnDist)
@@ -389,11 +392,15 @@ class StageVoteReleasePlugin @Inject constructor(
389392
390393 private fun Project.hideMavenPublishTasks () {
391394 allprojects {
395+ plugins.withType<PublishingPlugin > {
396+ tasks.named(PublishingPlugin .PUBLISH_LIFECYCLE_TASK_NAME ).hide()
397+ }
392398 plugins.withType<MavenPublishPlugin > {
393399 afterEvaluate {
394400 tasks.withType<PublishToMavenRepository >().hide()
395401 tasks.withType<PublishToMavenLocal >().hide()
396402 tasks.withType<GenerateModuleMetadata >().hide()
403+ tasks.named(" publishAllPublicationsTo${REPOSITORY_NAME .capitalize()} Repository" ).hide()
397404 val generatePomTasks = tasks.withType<GenerateMavenPom >()
398405 generatePomTasks.hide()
399406 tasks.register(" generatePom" ) {
@@ -532,44 +539,6 @@ class StageVoteReleasePlugin @Inject constructor(
532539 return pushPreviewSite
533540 }
534541
535- private fun Project.configureNexusStaging (releaseExt : ReleaseExtension ) {
536- plugins.withType<NexusStagingPlugin > {
537- tasks {
538- // Hide "deprecated" tasks from "./gradlew tasks"
539- named(" closeAndPromoteRepository" ).hide()
540- named(" promoteRepository" ).hide()
541- // Hide "internal" tasks
542- named(" createRepository" ).hide()
543- }
544- }
545- // The fields of releaseExt are not configured yet (the extension is not yet used in build scripts),
546- // so we populate NexusStaging properties after the project is configured
547- afterEvaluate {
548- configure<NexusStagingExtension > {
549- val nexus = project.the<ReleaseExtension >().nexus
550- packageGroup = nexus.packageGroup.get()
551- username = nexus.credentials.username(project)
552- password = nexus.credentials.password(project)
553- stagingProfileId = nexus.stagingProfileId.orNull
554- delayBetweenRetriesInMillis = 2000
555- numberOfRetries = (releaseExt.nexus.operationTimeout.get().toMillis() / 2000 ).toInt()
556- if (releaseExt.release.get()) {
557- repositoryDescription =
558- " Release ${releaseExt.componentName.get()} ${releaseExt.releaseTag.get()} (${releaseExt.rcTag.orNull ? : " " } )"
559- }
560- val nexusPublish = project.the<NexusPublishExtension >()
561- val repo = nexusPublish.repositories[REPOSITORY_NAME ]
562- serverUrl =
563- repo.run { if (nexusPublish.useStaging.get()) nexusUrl else snapshotRepositoryUrl }
564- .get().toString()
565-
566- stagingRepositoryId.set(
567- project.provider { releaseExt.repositoryIdStore.getOrLoad(REPOSITORY_NAME ) }
568- )
569- }
570- }
571- }
572-
573542 private fun URI.replacePath (path : String ) = URI (
574543 scheme,
575544 userInfo,
@@ -581,70 +550,46 @@ class StageVoteReleasePlugin @Inject constructor(
581550 )
582551
583552 private fun Project.configureNexusPublish (
553+ releaseExt : ReleaseExtension ,
584554 validateNexusCredentials : TaskProvider <* >,
585555 validateBeforeBuildingReleaseArtifacts : TaskProvider <* >
586556 ) {
587- val releaseExt = project.the<ReleaseExtension >()
588- val nexusPublish = the<NexusPublishExtension >()
589- val repo = nexusPublish.repositories.create(REPOSITORY_NAME ) {
590- nexusUrl.set(releaseExt.nexus.url.map { it.replacePath(" /service/local/" ) })
591- snapshotRepositoryUrl.set(releaseExt.nexus.url.map { it.replacePath(" /content/repositories/snapshots/" ) })
592- username.set(project.provider { releaseExt.nexus.credentials.username(project) })
593- password.set(project.provider { releaseExt.nexus.credentials.password(project) })
594- }
595-
596- nexusPublish.connectTimeout.set(releaseExt.nexus.connectTimeout)
597- nexusPublish.clientTimeout.set(releaseExt.nexus.operationTimeout)
598-
599- val rootInitStagingRepository = tasks.named(" initialize${repo.name.capitalize()} StagingRepository" )
600- // Use the same settings for all subprojects that apply MavenPublishPlugin
601- subprojects {
602- plugins.withType<MavenPublishPlugin > {
603- apply (plugin = " de.marcphilipp.nexus-publish" )
604-
605- configure<NexusPublishExtension > {
606- connectTimeout.set(nexusPublish.connectTimeout)
607- clientTimeout.set(nexusPublish.clientTimeout)
608- repositories.create(repo.name) {
609- nexusUrl.set(repo.nexusUrl)
610- snapshotRepositoryUrl.set(repo.snapshotRepositoryUrl)
611- username.set(repo.username)
612- password.set(repo.password)
613- }
614- useStaging.set(nexusPublish.useStaging)
615- }
557+ configure<NexusPublishExtension > {
558+ val repo = repositories.create(REPOSITORY_NAME ) {
559+ nexusUrl.set(releaseExt.nexus.url.map { it.replacePath(" /service/local/" ) })
560+ snapshotRepositoryUrl.set(releaseExt.nexus.url.map { it.replacePath(" /content/repositories/snapshots/" ) })
561+ username.set(project.provider { releaseExt.nexus.credentials.username(project) })
562+ password.set(project.provider { releaseExt.nexus.credentials.password(project) })
616563 }
617- plugins.withId(" de.marcphilipp.nexus-publish" ) {
618- tasks.withType<InitializeNexusStagingRepository >().configureEach {
619- // Allow for some parallelism, so the staging repository is created by the root task
620- dependsOn(rootInitStagingRepository)
621- }
564+ connectTimeout.set(releaseExt.nexus.connectTimeout)
565+ clientTimeout.set(releaseExt.nexus.operationTimeout)
566+ val nexus = releaseExt.nexus
567+ packageGroup.set(nexus.packageGroup)
568+ transitionCheckOptions {
569+ delayBetween.set(Duration .ofSeconds(10 ))
570+ maxRetries.set(nexus.operationTimeout.map { (1 + it.seconds / 10 ).toInt() })
622571 }
623- }
624-
625- // We don't know which project will be the first to initialize the staging repository,
626- // so we watch all the projects
627- // The goal of this block is to fetch and save the Id of newly created staging repository
628- allprojects {
629- plugins.withId(" de.marcphilipp.nexus-publish" ) {
630- // Hide unused task: https://github.com/marcphilipp/nexus-publish-plugin/issues/14
631- configure<NexusPublishExtension > {
632- repositories.whenObjectAdded {
633- tasks.named(" publishTo${name.capitalize()} " ) {
634- group = null
635- }
636- }
572+ repositoryDescription.set(project.provider {
573+ if (releaseExt.release.get()) {
574+ project.run { " $group :$name :$version " }
575+ } else {
576+ " Release ${releaseExt.componentName.get()} ${releaseExt.releaseTag.get()} (${releaseExt.rcTag.orNull ? : " " } )"
637577 }
638- tasks.withType<InitializeNexusStagingRepository >().configureEach {
639- dependsOn(validateBeforeBuildingReleaseArtifacts)
640- dependsOn(validateNexusCredentials)
641- doLast {
642- // nexus-publish puts stagingRepositoryId to NexusStagingExtension so we get it from there
643- val repoName = this @configureEach.repositoryName.get()
644- val stagingRepositoryId =
645- rootProject.the<NexusStagingExtension >().stagingRepositoryId.get()
646- releaseExt.repositoryIdStore[repoName] = stagingRepositoryId
647- }
578+ })
579+
580+ tasks.named<ReleaseNexusStagingRepository >(" release${REPOSITORY_NAME .capitalize()} StagingRepository" ) {
581+ stagingRepositoryId.set(project.provider { releaseExt.repositoryIdStore.getOrLoad(REPOSITORY_NAME ) })
582+ }
583+ tasks.named<InitializeNexusStagingRepository >(" initialize${repo.name.capitalize()} StagingRepository" ) {
584+ dependsOn(validateBeforeBuildingReleaseArtifacts)
585+ dependsOn(validateNexusCredentials)
586+ doLast {
587+ val repoName = repository.get().name
588+ val closeRepoTask =
589+ rootProject.tasks.named<CloseNexusStagingRepository >(" close${repoName.capitalize()} StagingRepository" )
590+ val stagingRepositoryId =
591+ closeRepoTask.get().stagingRepositoryId.get()
592+ releaseExt.repositoryIdStore[repoName] = stagingRepositoryId
648593 }
649594 }
650595 }
0 commit comments