@@ -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
@@ -48,6 +48,7 @@ import org.gradle.kotlin.dsl.configure
4848import org.gradle.kotlin.dsl.create
4949import org.gradle.kotlin.dsl.get
5050import org.gradle.kotlin.dsl.invoke
51+ import org.gradle.kotlin.dsl.named
5152import org.gradle.kotlin.dsl.provideDelegate
5253import org.gradle.kotlin.dsl.register
5354import org.gradle.kotlin.dsl.the
@@ -58,6 +59,7 @@ import org.gradle.plugins.signing.SigningPlugin
5859import java.io.File
5960import java.net.URI
6061import java.nio.charset.StandardCharsets
62+ import java.time.Duration
6163import javax.inject.Inject
6264
6365class 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