|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +import io.github.zenhelix.gradle.plugin.MavenCentralUploaderPlugin.Companion.MAVEN_CENTRAL_PORTAL_NAME |
| 18 | +import io.github.zenhelix.gradle.plugin.extension.MavenCentralUploaderExtension |
17 | 19 | import io.github.zenhelix.gradle.plugin.extension.PublishingType |
| 20 | +import io.github.zenhelix.gradle.plugin.task.PublishBundleMavenCentralTask |
| 21 | +import io.github.zenhelix.gradle.plugin.task.ZipDeploymentTask |
18 | 22 | import java.time.Duration |
| 23 | +import org.gradle.api.publish.plugins.PublishingPlugin.PUBLISH_TASK_GROUP |
19 | 24 | import org.jetbrains.gradle.ext.settings |
20 | 25 | import org.jetbrains.gradle.ext.taskTriggers |
21 | 26 |
|
@@ -56,15 +61,120 @@ mavenCentralPortal { |
56 | 61 | // baseUrl = "https://central.sonatype.com" |
57 | 62 | uploader { |
58 | 63 | // 2 seconds * 3600 = 7200 seconds = 2hrs |
59 | | - statusCheckDelay = Duration.ofSeconds(2) |
60 | | - maxStatusChecks = 3600 |
| 64 | + delayRetriesStatusCheck = Duration.ofSeconds(2) |
| 65 | + maxRetriesStatusCheck = 3600 |
| 66 | + |
| 67 | + aggregate { |
| 68 | + // Aggregate submodules into a single archive |
| 69 | + modules = true |
| 70 | + // Aggregate publications into a single archive for each module |
| 71 | + modulePublications = true |
| 72 | + } |
61 | 73 | } |
62 | 74 | } |
63 | 75 |
|
| 76 | +val mavenCentralDeploymentZipAggregation by configurations.creating |
| 77 | + |
| 78 | +mavenCentralDeploymentZipAggregation.isTransitive = true |
| 79 | + |
| 80 | +val zipAggregateMavenCentralDeployment by |
| 81 | + tasks.registering(Zip::class) { |
| 82 | + group = PUBLISH_TASK_GROUP |
| 83 | + description = "Generates the aggregated Maven publication zip file." |
| 84 | + |
| 85 | + inputs.files(mavenCentralDeploymentZipAggregation) |
| 86 | + from(mavenCentralDeploymentZipAggregation.map { zipTree(it) }) |
| 87 | + // archiveFileName = mavenCentralPortal.deploymentName.orElse(project.name) |
| 88 | + destinationDirectory.set(layout.buildDirectory.dir("aggregatedDistribution")) |
| 89 | + doLast { logger.lifecycle("Built aggregated distribution ${archiveFile.get()}") } |
| 90 | + } |
| 91 | + |
| 92 | +val publishAggregateMavenCentralDeployment by |
| 93 | + tasks.registering(PublishBundleMavenCentralTask::class) { |
| 94 | + group = PUBLISH_TASK_GROUP |
| 95 | + description = |
| 96 | + "Publishes the aggregated Maven publications $MAVEN_CENTRAL_PORTAL_NAME repository." |
| 97 | + |
| 98 | + dependsOn(zipAggregateMavenCentralDeployment) |
| 99 | + inputs.file(zipAggregateMavenCentralDeployment.flatMap { it.archiveFile }) |
| 100 | + |
| 101 | + val task = this |
| 102 | + |
| 103 | + project.extensions.configure<MavenCentralUploaderExtension> { |
| 104 | + val ext = this |
| 105 | + task.baseUrl.set(ext.baseUrl) |
| 106 | + task.credentials.set( |
| 107 | + ext.credentials.username.flatMap { username -> |
| 108 | + ext.credentials.password.map { password -> |
| 109 | + io.github.zenhelix.gradle.plugin.client.model.Credentials.UsernamePasswordCredentials( |
| 110 | + username, |
| 111 | + password, |
| 112 | + ) |
| 113 | + } |
| 114 | + } |
| 115 | + ) |
| 116 | + |
| 117 | + task.publishingType.set( |
| 118 | + ext.publishingType.map { |
| 119 | + when (it) { |
| 120 | + PublishingType.AUTOMATIC -> |
| 121 | + io.github.zenhelix.gradle.plugin.client.model.PublishingType.AUTOMATIC |
| 122 | + PublishingType.USER_MANAGED -> |
| 123 | + io.github.zenhelix.gradle.plugin.client.model.PublishingType.USER_MANAGED |
| 124 | + } |
| 125 | + } |
| 126 | + ) |
| 127 | + task.deploymentName.set(ext.deploymentName) |
| 128 | + |
| 129 | + task.maxRetriesStatusCheck.set(ext.uploader.maxRetriesStatusCheck) |
| 130 | + task.delayRetriesStatusCheck.set(ext.uploader.delayRetriesStatusCheck) |
| 131 | + |
| 132 | + task.zipFile.set(zipAggregateMavenCentralDeployment.flatMap { it.archiveFile }) |
| 133 | + } |
| 134 | + } |
| 135 | + |
64 | 136 | // Configure the 'io.github.zenhelix.maven-central-publish' plugin to all projects |
65 | 137 | allprojects.forEach { p -> |
66 | 138 | p.pluginManager.withPlugin("maven-publish") { |
67 | 139 | p.pluginManager.apply("io.github.zenhelix.maven-central-publish") |
| 140 | + p.extensions.configure<MavenCentralUploaderExtension> { |
| 141 | + val aggregatedMavenCentralDeploymentZipPart by p.configurations.creating |
| 142 | + aggregatedMavenCentralDeploymentZipPart.description = "Maven central publication zip" |
| 143 | + val aggregatedMavenCentralDeploymentZipPartElements by p.configurations.creating |
| 144 | + aggregatedMavenCentralDeploymentZipPartElements.description = |
| 145 | + "Elements for the Maven central publication zip" |
| 146 | + aggregatedMavenCentralDeploymentZipPartElements.isCanBeResolved = false |
| 147 | + aggregatedMavenCentralDeploymentZipPartElements.extendsFrom( |
| 148 | + aggregatedMavenCentralDeploymentZipPart |
| 149 | + ) |
| 150 | + aggregatedMavenCentralDeploymentZipPartElements.attributes { |
| 151 | + attribute( |
| 152 | + Usage.USAGE_ATTRIBUTE, |
| 153 | + project.getObjects().named(Usage::class.java, "publication"), |
| 154 | + ) |
| 155 | + } |
| 156 | + |
| 157 | + val aggregatemavenCentralDeployment by |
| 158 | + p.tasks.registering { |
| 159 | + val zip = p.tasks.findByName("zipDeploymentMavenPublication") as ZipDeploymentTask |
| 160 | + dependsOn(zip) |
| 161 | + outputs.file(zip.archiveFile.get().asFile) |
| 162 | + } |
| 163 | + |
| 164 | + val artifact = |
| 165 | + p.artifacts.add( |
| 166 | + aggregatedMavenCentralDeploymentZipPart.name, |
| 167 | + aggregatemavenCentralDeployment, |
| 168 | + ) { |
| 169 | + builtBy(aggregatemavenCentralDeployment) |
| 170 | + } |
| 171 | + aggregatedMavenCentralDeploymentZipPart.outgoing.artifact(artifact) |
| 172 | + |
| 173 | + rootProject.dependencies.add( |
| 174 | + mavenCentralDeploymentZipAggregation.name, |
| 175 | + rootProject.dependencies.project(p.path, aggregatedMavenCentralDeploymentZipPart.name), |
| 176 | + ) |
| 177 | + } |
68 | 178 | } |
69 | 179 | } |
70 | 180 |
|
|
0 commit comments