[repo] Migrate 'preparePublication' task into buildSrc

This commit is contained in:
Yahor Berdnikau
2023-07-02 16:11:31 +02:00
committed by Space Team
parent 7bfe59253f
commit 1fdda8962d
6 changed files with 116 additions and 77 deletions
-29
View File
@@ -1,29 +0,0 @@
task preparePublication {
def properties = project.properties
assert project.version != 'unspecified'
Map<String, String> repositoryProviders = ['sonatype-nexus-staging' : 'sonatype', 'sonatype-nexus-snapshots' : 'sonatype']
project.ext.isRelease = !project.version.toString().contains('-SNAPSHOT')
String repo = properties["deployRepo"] ?: properties['deploy-repo']
String repoProvider = repositoryProviders.get(repo, repo)
project.ext.isSonatypePublish = repoProvider == 'sonatype'
project.ext.isSonatypeRelease = isSonatypePublish && isRelease
String deployRepoUrl = properties["deployRepoUrl"] ?: properties["deploy-url"]
String deployFolder = properties["deployRepoFolder"] != null ? "file://${rootProject.buildDir}/${properties["deployRepoFolder"]}" : null
String sonatypeSnapshotsUrl = (isSonatypePublish && !isRelease) ? "https://oss.sonatype.org/content/repositories/snapshots/" : null
String deployUrlFromParameters = deployRepoUrl ?: deployFolder ?: sonatypeSnapshotsUrl
project.ext.isDeployStagingRepoGenerationRequired = project.ext.isSonatypeRelease && deployUrlFromParameters == null
ext.repoUrl = (deployUrlFromParameters ?: "file://${rootProject.buildDir}/repo").toString()
logger.info("Deployment repository preliminary url: ${ext.repoUrl} ($repoProvider)")
ext.username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
ext.password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]
doLast {
println("Deployment repository url: ${ext.repoUrl}")
}
}
-38
View File
@@ -1,38 +0,0 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.2'
}
}
import groovyx.net.http.RESTClient
preparePublication {
doFirst {
def client = new RESTClient()
client.uri = 'https://oss.sonatype.org/service/local/staging/profiles/169b36e205a64e/start'
client.auth.basic(username, password)
def params = [
body: "<promoteRequest><data><description>Repository for publishing $version</description></data></promoteRequest>",
contentType: groovyx.net.http.ContentType.XML,
requestContentType: groovyx.net.http.ContentType.XML
]
def rootNode
try {
def serverResponse = client.post(params)
rootNode = serverResponse.getData()
} catch (groovyx.net.http.HttpResponseException e) {
throw new GradleException(e.getResponse().getData().toString(), e)
}
def repoId = rootNode.data.stagedRepositoryId.text()
ext.repoUrl = "https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/".toString()
println "##teamcity[setParameter name='system.deploy-url' value='${repoUrl}']"
}
}