Create staging sonatype repository manually and change deploy-url parameter.

This is required to ensure that both gradle and maven build publish their artifacts
to the same sonatype staging repository.

Override deployment repository url for publishing snapshots to sonatype.
This commit is contained in:
Ilya Gorbunov
2017-04-04 20:31:12 +03:00
parent c5e52b124b
commit 324445fa7d
2 changed files with 78 additions and 12 deletions

View File

@@ -93,16 +93,45 @@ static def manifestAttributes(Manifest manifest, Project project, String compone
}
}
task preparePublication {
def properties = project.properties
Map<String, String> repositoryProviders = ['sonatype-nexus-staging' : 'sonatype', 'sonatype-nexus-snapshots' : 'sonatype']
project.ext.isRelease = !project.version.toString().contains('-SNAPSHOT')
String repo = properties['deploy-repo']
String repoProvider = repositoryProviders.get(repo, repo)
project.ext.isSonatypePublish = repoProvider == 'sonatype'
project.ext.isSonatypeRelease = isSonatypePublish && isRelease
project.ext['signing.keyId'] = project.properties['kotlin.key.name']
project.ext['signing.password'] = project.properties['kotlin.key.passphrase']
String sonatypeSnapshotsUrl = (isSonatypePublish && !isRelease) ? "https://oss.sonatype.org/content/repositories/snapshots/" : null
ext.repoUrl = properties["deployRepoUrl"] ?: sonatypeSnapshotsUrl ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo"
ext.username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
ext.password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]
doLast {
println("Deployment respository url: $repoUrl")
}
}
if (isSonatypeRelease) {
println 'Applying configuration for sonatype release'
apply from: 'prepareSonatypeStaging.gradle'
}
static def configurePublishing(Project project) {
project.configure(project) {
apply plugin: 'maven'
apply plugin: 'signing'
project.ext['signing.keyId'] = project.properties['kotlin.key.name']
project.ext['signing.password'] = project.properties['kotlin.key.passphrase']
signing {
required { (project.properties["signingRequired"] ?: false) }
required { (project.properties["signingRequired"] ?: project.isSonatypeRelease) }
sign configurations.archives
}
@@ -117,13 +146,12 @@ static def configurePublishing(Project project) {
}
uploadArchives {
def properties = project.properties
Map<String, String> repositoryProviders = ['sonatype-nexus-staging' : 'sonatype', 'sonatype-nexus-snapshots' : 'sonatype']
String repo = properties['deploy-repo']
String repoProvider = repositoryProviders.get(repo, repo)
String repoUrl = properties["deployRepoUrl"] ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo"
String username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
String password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]
def prepareTask = rootProject.preparePublication
dependsOn prepareTask
doFirst {
repositories.mavenDeployer.repository.url = prepareTask.repoUrl
}
repositories {
mavenDeployer {
@@ -132,8 +160,8 @@ static def configurePublishing(Project project) {
signing.signPom(deployment)
}
repository(url: repoUrl) {
authentication(userName: username, password: password)
repository(url: prepareTask.repoUrl) {
authentication(userName: prepareTask.username, password: prepareTask.password)
}
pom.project {
name "${project.group}:${project.name}"

View File

@@ -0,0 +1,38 @@
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 = "http://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/"
println "##teamcity[setParameter name='system.deploy-url' value='${repoUrl}']"
}
}