forked from conductor-oss/conductor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.gradle
More file actions
131 lines (114 loc) · 5.09 KB
/
deploy.gradle
File metadata and controls
131 lines (114 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
subprojects {
apply plugin: 'maven-publish'
apply plugin: 'java-library'
apply plugin: 'signing'
group = 'org.conductoross'
java {
withSourcesJar()
withJavadocJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'Conductor OSS'
description = 'Conductor OSS build.'
url = 'https://github.com/conductor-oss/conductor'
scm {
connection = 'scm:git:git://github.com/conductor-oss/conductor.git'
developerConnection = 'scm:git:ssh://github.com/conductor-oss/conductor.git'
url = 'https://github.com/conductor-oss/conductor'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
organization = 'Conductor OSS'
organizationUrl = 'https://conductor-oss.org/'
name = 'Conductor OSS'
}
}
}
}
}
repositories {
maven {
url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
credentials {
username project.properties.username
password project.properties.password
}
}
}
}
signing {
def signingKeyId = findProperty('signingKeyId')
if (signingKeyId) {
def signingKey = findProperty('signingKey')
def signingPassword = findProperty('signingPassword')
if (signingKeyId && signingKey && signingPassword) {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
}
sign publishing.publications
}
}
task promoteToMavenCentral {
group = 'publishing'
description = 'Promotes staged artifacts to Maven Central'
onlyIf {
project.hasProperty('mavenCentral') &&
project.hasProperty('username') &&
project.hasProperty('password') &&
!project.version.endsWith('-SNAPSHOT')
}
doLast {
def username = project.properties['username']
def password = project.properties['password']
// Create base64 encoded token for authentication
def token = "${username}:${password}".bytes.encodeBase64().toString()
// Get open staging repositories
def response = new URL("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories")
.openConnection()
response.setRequestProperty("Authorization", "Basic ${token}")
response.setRequestProperty("Content-Type", "application/json")
def repositories = new groovy.json.JsonSlurper().parse(response.inputStream)
// Promote each open repository
repositories.repositories.each { repo ->
if (repo.state == "open") {
project.logger.lifecycle("Promoting repository ${repo.key}")
def promoteUrl = new URL("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/${repo.key}?publishing_type=automatic")
def connection = promoteUrl.openConnection()
connection.setRequestMethod("POST")
connection.setRequestProperty("Authorization", "Basic ${token}")
connection.setRequestProperty("Content-Type", "application/json")
def responseCode = connection.responseCode
if (responseCode == 200) {
project.logger.lifecycle("Successfully promoted repository ${repo.key}")
} else {
def errorStream = connection.errorStream
def errorBody = errorStream ? errorStream.text : "No error body available"
def errorMessage = "Failed to promote repository ${repo.key}. Response code: ${responseCode}. Response message: ${connection.responseMessage}. Error body: ${errorBody}"
project.logger.error(errorMessage)
//throw new GradleException(errorMessage)
}
}
}
}
}
tasks.matching { it.name == 'publish' }.configureEach { publishTask ->
publishTask.finalizedBy tasks.promoteToMavenCentral
}
}