Skip to content

Commit 4a4d6ca

Browse files
authored
Automate publishing (#190)
1 parent 8b30a47 commit 4a4d6ca

File tree

11 files changed

+527
-259
lines changed

11 files changed

+527
-259
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jdk:
1313
- oraclejdk8
1414
- oraclejdk9
1515
- oraclejdk11
16-
- openjdk7
1716
- openjdk8
1817
- openjdk10
1918

build.gradle

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
1-
buildscript {
2-
}
3-
41
allprojects {
5-
apply plugin: 'maven'
6-
apply plugin: 'signing'
72

83
repositories {
94
jcenter()
105
mavenCentral()
116
}
127

13-
signing {
14-
sign configurations.archives
15-
}
168
project.ext.set("publishGroupId", group)
17-
}
18-
19-
subprojects {
20-
tasks.withType(Test) {
21-
environment 'CLOUDINARY_URL', System.getProperty('CLOUDINARY_URL')
22-
maxParallelForks = Runtime.runtime.availableProcessors()
23-
24-
// show standard out and standard error of the test JVM(s) on the console
25-
testLogging.showStandardStreams = true
26-
}
27-
}
9+
}

cloudinary-core/build.gradle

Lines changed: 90 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,111 @@
1-
apply from: "../java_shared.gradle"
2-
3-
task ciTest( type: Test ) {
1+
plugins {
2+
id 'java-library'
3+
id 'signing'
4+
id 'maven-publish'
5+
id 'io.codearte.nexus-staging' version '0.21.1'
6+
id "de.marcphilipp.nexus-publish" version "0.4.0"
47
}
58

9+
task ciTest( type: Test )
10+
611
dependencies {
7-
testCompile group: 'org.hamcrest', name: 'java-hamcrest', version:'2.0.0.0'
8-
testCompile group: 'pl.pragmatists', name: 'JUnitParams', version:'1.0.5'
9-
testCompile group: 'junit', name: 'junit', version:'4.12'
12+
testImplementation "org.hamcrest:java-hamcrest:2.0.0.0"
13+
testImplementation group: 'pl.pragmatists', name: 'JUnitParams', version: '1.0.5'
14+
testImplementation group: 'junit', name: 'junit', version: '4.12'
1015
}
1116

12-
uploadArchives {
13-
repositories {
14-
mavenDeployer {
15-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
17+
apply from: "../java_shared.gradle"
1618

17-
repository(url: publishRepo) {
18-
authentication(userName: project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : "", password: project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : "")
19-
}
19+
if (hasProperty("ossrhPassword")) {
20+
signing {
21+
sign configurations.archives
22+
}
2023

21-
snapshotRepository(url: snapshotRepo) {
22-
authentication(userName: project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : "", password: project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : "")
23-
}
2424

25-
pom.project {
26-
groupId publishGroupId
27-
artifactId 'cloudinary-core'
28-
name 'Cloudinary Core Library'
29-
description publishDescription
30-
packaging jar
31-
version version
25+
nexusStaging {
26+
packageGroup = group
27+
username = project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : ""
28+
password = project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : ""
29+
}
3230

33-
url githubUrl
31+
publishing {
32+
publications {
33+
mavenJava(MavenPublication) {
34+
from components.java
35+
artifact sourcesJar
36+
artifact javadocJar
37+
pom {
38+
name = 'Cloudinary Core Library'
39+
packaging = 'jar'
40+
groupId = publishGroupId
41+
artifactId = 'cloudinary-core'
42+
description = publishDescription
43+
url = githubUrl
44+
licenses {
45+
license {
46+
name = licenseName
47+
url = licenseUrl
48+
}
49+
}
3450

35-
scm {
36-
connection scmConnection
37-
developerConnection scmDeveloperConnection
38-
url scmUrl
51+
developers {
52+
developer {
53+
id = developerId
54+
name = developerName
55+
email = developerEmail
56+
}
57+
}
58+
scm {
59+
connection = scmConnection
60+
developerConnection = scmDeveloperConnection
61+
url = scmUrl
62+
}
3963
}
4064

41-
licenses {
42-
license {
43-
name licenseName
44-
url licenseUrl
65+
pom.withXml {
66+
def pomFile = file("${project.buildDir}/generated-pom.xml")
67+
writeTo(pomFile)
68+
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
69+
artifact(pomAscFile) {
70+
classifier = null
71+
extension = 'pom.asc'
4572
}
4673
}
4774

48-
developers {
49-
developer {
50-
id developerId
51-
name developerName
52-
email developerEmail
75+
// create the signed artifacts
76+
project.tasks.signArchives.signatureFiles.each {
77+
artifact(it) {
78+
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
79+
if (matcher.find()) {
80+
classifier = matcher.group(1)
81+
} else {
82+
classifier = null
83+
}
84+
extension = 'jar.asc'
5385
}
5486
}
5587
}
5688
}
89+
90+
nexusPublishing {
91+
repositories {
92+
sonatype {
93+
username = project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : ""
94+
password = project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : ""
95+
}
96+
}
97+
}
98+
99+
model {
100+
tasks.generatePomFileForMavenJavaPublication {
101+
destination = file("$buildDir/generated-pom.xml")
102+
}
103+
tasks.publishMavenJavaPublicationToMavenLocal {
104+
dependsOn project.tasks.signArchives
105+
}
106+
tasks.publishMavenJavaPublicationToSonatypeRepository {
107+
dependsOn project.tasks.signArchives
108+
}
109+
}
57110
}
58111
}

cloudinary-http42/build.gradle

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
plugins {
2+
id 'java-library'
3+
id 'signing'
4+
id 'maven-publish'
5+
id 'io.codearte.nexus-staging' version '0.21.1'
6+
id "de.marcphilipp.nexus-publish" version "0.4.0"
7+
}
8+
19
apply from: "../java_shared.gradle"
210

311
task ciTest( type: Test ) {
@@ -18,59 +26,96 @@ dependencies {
1826
testCompile group: 'junit', name: 'junit', version: '4.12'
1927
}
2028

21-
uploadArchives {
22-
repositories {
23-
mavenDeployer {
24-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
29+
if (hasProperty("ossrhPassword")) {
2530

26-
repository(url: publishRepo) {
27-
authentication(userName: project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : "", password: project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : "")
28-
}
29-
30-
snapshotRepository(url: snapshotRepo) {
31-
authentication(userName: project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : "", password: project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : "")
32-
}
31+
signing {
32+
sign configurations.archives
33+
}
3334

34-
pom.project {
35-
groupId publishGroupId
36-
artifactId 'cloudinary-http42'
37-
name 'Cloudinary Apache HTTP 4.2 Library'
38-
description publishDescription
39-
packaging jar
40-
version version
35+
nexusStaging {
36+
packageGroup = group
37+
username = project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : ""
38+
password = project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : ""
39+
}
4140

42-
url githubUrl
41+
publishing {
42+
publications {
43+
mavenJava(MavenPublication) {
44+
from components.java
45+
artifact sourcesJar
46+
artifact javadocJar
47+
pom {
48+
name = 'Cloudinary Apache HTTP 4.2 Library'
49+
packaging = 'jar'
50+
groupId = publishGroupId
51+
artifactId = 'cloudinary-http42'
52+
description = publishDescription
53+
url = githubUrl
54+
licenses {
55+
license {
56+
name = licenseName
57+
url = licenseUrl
58+
}
59+
}
4360

44-
scm {
45-
connection scmConnection
46-
developerConnection scmDeveloperConnection
47-
url scmUrl
61+
developers {
62+
developer {
63+
id = developerId
64+
name = developerName
65+
email = developerEmail
66+
}
67+
}
68+
scm {
69+
connection = scmConnection
70+
developerConnection = scmDeveloperConnection
71+
url = scmUrl
72+
}
4873
}
4974

50-
licenses {
51-
license {
52-
name licenseName
53-
url licenseUrl
75+
pom.withXml {
76+
def pomFile = file("${project.buildDir}/generated-pom.xml")
77+
writeTo(pomFile)
78+
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
79+
artifact(pomAscFile) {
80+
classifier = null
81+
extension = 'pom.asc'
5482
}
5583
}
5684

57-
developers {
58-
developer {
59-
id developerId
60-
name developerName
61-
email developerEmail
85+
// create the signed artifacts
86+
project.tasks.signArchives.signatureFiles.each {
87+
artifact(it) {
88+
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
89+
if (matcher.find()) {
90+
classifier = matcher.group(1)
91+
} else {
92+
classifier = null
93+
}
94+
extension = 'jar.asc'
6295
}
6396
}
6497
}
98+
}
6599

66-
pom.whenConfigured { pom ->
67-
pom.dependencies.forEach { dep ->
68-
if (dep.getVersion() == "unspecified") {
69-
dep.setGroupId(publishGroupId)
70-
dep.setVersion(version)
71-
}
100+
nexusPublishing {
101+
repositories {
102+
sonatype {
103+
username = project.hasProperty("ossrhUsername") ? project.ext["ossrhUsername"] : ""
104+
password = project.hasProperty("ossrhPassword") ? project.ext["ossrhPassword"] : ""
72105
}
73106
}
74107
}
108+
109+
model {
110+
tasks.generatePomFileForMavenJavaPublication {
111+
destination = file("$buildDir/generated-pom.xml")
112+
}
113+
tasks.publishMavenJavaPublicationToMavenLocal {
114+
dependsOn project.tasks.signArchives
115+
}
116+
tasks.publishMavenJavaPublicationToSonatypeRepository {
117+
dependsOn project.tasks.signArchives
118+
}
119+
}
75120
}
76121
}

0 commit comments

Comments
 (0)