Skip to content

Commit f7fffea

Browse files
committed
Gradle: add Maven Central publishing support.
1 parent b8f70f9 commit f7fffea

12 files changed

Lines changed: 219 additions & 137 deletions

File tree

build.gradle

Lines changed: 23 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@
1414
* limitations under the License.
1515
*/
1616

17+
plugins {
18+
// https://github.com/ben-manes/gradle-versions-plugin/releases
19+
id("com.github.ben-manes.versions") version "0.46.0"
20+
// https://github.com/gradle-nexus/publish-plugin/releases
21+
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
22+
}
23+
24+
1725
allprojects {
1826
apply plugin: 'eclipse'
1927
apply plugin: 'jacoco'
2028
apply plugin: 'java-library'
21-
apply plugin: 'maven'
22-
apply plugin: 'signing'
2329

2430
group = 'com.google.endpoints'
2531

2632
java {
2733
toolchain {
2834
languageVersion = JavaLanguageVersion.of(8)
2935
}
36+
withJavadocJar()
37+
withSourcesJar()
3038
}
3139

3240
jacocoTestReport {
@@ -78,88 +86,20 @@ subprojects {
7886
}
7987
}
8088

81-
def configureMaven(project, projectName, projectDescription) {
82-
configure(project) {
83-
task javadocJar(type: Jar) {
84-
classifier = 'javadoc'
85-
from javadoc
86-
}
87-
88-
task sourcesJar(type: Jar) {
89-
classifier = 'sources'
90-
from sourceSets.main.allSource
91-
}
92-
93-
artifacts {
94-
archives javadocJar, sourcesJar
95-
}
96-
97-
signing {
98-
required false
99-
sign configurations.archives
100-
}
101-
102-
uploadArchives {
103-
repositories {
104-
mavenDeployer {
105-
def tmpSnapshotRepo = "http://104.197.230.53:8081/nexus/content/repositories/snapshots/"
106-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
107-
108-
String stagingUrl
109-
if (rootProject.hasProperty('repositoryId')) {
110-
stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
111-
rootProject.repositoryId
112-
} else {
113-
stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
114-
}
115-
def configureAuth = {
116-
if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
117-
authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
118-
}
119-
}
120-
repository(url: stagingUrl, configureAuth)
121-
snapshotRepository(url: tmpSnapshotRepo) {
122-
authentication(userName: privateOssrhUsername, password: privateOssrhPassword)
123-
}
124-
125-
pom.project {
126-
name projectName
127-
description projectDescription
128-
packaging 'jar'
129-
url 'https://cloud.google.com/endpoints/docs/frameworks/java'
130-
131-
scm {
132-
connection 'scm:git:https://github.com/cloudendpoints/endpoints-management-java'
133-
developerConnection 'scm:git:https://github.com/cloudendpoints/endpoints-management-java'
134-
url 'scm:git:https://github.com/cloudendpoints/endpoints-management-java'
135-
}
136-
137-
licenses {
138-
license {
139-
name 'The Apache License, Version 2.0'
140-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
141-
}
142-
}
143-
144-
developers {
145-
developer {
146-
id 'temiola@google.com'
147-
name 'Tim Emiola'
148-
email 'temiola@google.com'
149-
organization = "Google, Inc."
150-
organizationUrl "https://www.google.com"
151-
}
152-
developer {
153-
id 'yangguan@google.com'
154-
name 'Yang Guan'
155-
email 'yangguan@google.com'
156-
organization = "Google, Inc."
157-
organizationUrl "https://www.google.com"
158-
}
159-
}
160-
}
161-
}
89+
// Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/
90+
// This plugin ensures a separate, named staging repo is created for each build when publishing.
91+
nexusPublishing {
92+
packageGroup.set("com.uwetrottmann")
93+
repositories {
94+
sonatype {
95+
if (project.hasProperty("SONATYPE_NEXUS_USERNAME") && project.hasProperty("SONATYPE_NEXUS_PASSWORD")) {
96+
println("nexusPublishing credentials supplied.")
97+
username.set(project.property("SONATYPE_NEXUS_USERNAME").toString())
98+
password.set(project.property("SONATYPE_NEXUS_PASSWORD").toString())
99+
} else {
100+
println("nexusPublishing credentials NOT supplied.")
162101
}
163102
}
164103
}
165104
}
105+

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}

buildSrc/settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Recommended to create, but keep empty
2+
// https://docs.gradle.org/current/userguide/custom_plugins.html#sec:precompiled_plugins
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Configures common publishing settings
2+
3+
plugins {
4+
id("maven-publish")
5+
id("signing")
6+
}
7+
8+
// Make javadoc task errors not break the build.
9+
if (JavaVersion.current().isJava8Compatible) {
10+
tasks.withType<Javadoc> {
11+
isFailOnError = false
12+
}
13+
}
14+
15+
publishing {
16+
// Note: Sonatype repo created by publish-plugin, see root build.gradle.
17+
18+
publications {
19+
create<MavenPublication>("mavenJava") {
20+
// Note: Projects set additional specific properties.
21+
pom {
22+
packaging = "jar"
23+
url.set("https://github.com/UweTrottmann/endpoints-management-java/")
24+
25+
licenses {
26+
license {
27+
name.set("The Apache License, Version 2.0")
28+
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
29+
distribution.set("repo")
30+
}
31+
}
32+
33+
developers {
34+
developer {
35+
name.set("Uwe Trottmann")
36+
email.set("uwe@uwetrottmann.com")
37+
organization.set("Uwe Trottmann")
38+
organizationUrl.set("https://www.uwetrottmann.com")
39+
}
40+
}
41+
42+
scm {
43+
connection.set("scm:git@github.com:UweTrottmann/endpoints-management-java.git")
44+
developerConnection.set("scm:git@github.com:UweTrottmann/endpoints-management-java.git")
45+
url.set("https://github.com/UweTrottmann/endpoints-management-java/")
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
signing {
53+
// https://docs.gradle.org/current/userguide/signing_plugin.html#sec:using_gpg_agent
54+
useGpgCmd()
55+
sign(publishing.publications["mavenJava"])
56+
}

endpoints-auth/build.gradle

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
configureMaven(
18-
project,
19-
'Endpoints API Management - Authentication',
20-
'Enables authentication by multiple authentication providers'
21-
)
22-
archivesBaseName = 'endpoints-management-auth'
17+
plugins {
18+
id("ut-publish")
19+
}
20+
21+
version = "1.0.15-SNAPSHOT"
22+
23+
// Set project-specific publishing properties
24+
publishing {
25+
publications {
26+
mavenJava(MavenPublication) {
27+
artifactId = "endpoints-management-auth"
28+
from components.java
29+
pom {
30+
name.set("Endpoints API Management - Authentication")
31+
description.set("Enables authentication by multiple authentication providers")
32+
}
33+
}
34+
}
35+
}
2336

2437
configurations {
2538
integrationTestCompile.extendsFrom testImplementation

endpoints-control-api-client/build.gradle

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
buildscript {
18-
repositories {
19-
mavenCentral()
20-
}
21-
dependencies { classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10' }
17+
plugins {
18+
id("ut-publish")
2219
}
23-
archivesBaseName = 'endpoints-management-api-client'
2420

25-
configureMaven(
26-
project,
27-
'Endpoints Management - API service client',
28-
'Contains the generated http client for the service control service'
29-
)
21+
version = "1.0.15-SNAPSHOT"
22+
23+
// Set project-specific publishing properties
24+
publishing {
25+
publications {
26+
mavenJava(MavenPublication) {
27+
artifactId = "endpoints-management-api-client"
28+
from components.java
29+
pom {
30+
name.set("Endpoints Management - API service client")
31+
description.set("Contains the generated http client for the service control service")
32+
}
33+
}
34+
}
35+
}
3036

3137
dependencies {
3238
implementation("com.google.api-client:google-api-client-protobuf:${googleApiClientProtobufVersion}") {

endpoints-control-appengine/build.gradle

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
configureMaven(
18-
project,
19-
'Endpoints API Management on GAE',
20-
'Provide access control to managed services on Google App Engine'
21-
)
22-
archivesBaseName = 'endpoints-management-control-appengine'
17+
plugins {
18+
id("ut-publish")
19+
}
20+
21+
version = "1.0.15-SNAPSHOT"
22+
23+
// Set project-specific publishing properties
24+
publishing {
25+
publications {
26+
mavenJava(MavenPublication) {
27+
artifactId = "endpoints-management-control-appengine"
28+
from components.java
29+
pom {
30+
name.set("Endpoints API Management on GAE")
31+
description.set("Provide access control to managed services on Google App Engine")
32+
}
33+
}
34+
}
35+
}
2336

2437
dependencies {
2538
api project(":endpoints-control")

endpoints-control/build.gradle

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,25 @@ buildscript {
2121
dependencies { classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10' }
2222
}
2323

24-
configureMaven(
25-
project,
26-
'Endpoints API Management',
27-
'Provide access control for managed services'
28-
)
29-
archivesBaseName = 'endpoints-management-control'
24+
plugins {
25+
id("ut-publish")
26+
}
27+
28+
version = "1.0.15-SNAPSHOT"
29+
30+
// Set project-specific publishing properties
31+
publishing {
32+
publications {
33+
mavenJava(MavenPublication) {
34+
artifactId = "endpoints-management-control"
35+
from components.java
36+
pom {
37+
name.set("Endpoints API Management")
38+
description.set("Provide access control for managed services")
39+
}
40+
}
41+
}
42+
}
3043

3144
test {
3245
testLogging {

endpoints-framework-auth/build.gradle

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
configureMaven(
18-
project,
19-
'Endpoints API Management - Framework Auth Integration',
20-
'Enables use of endpoints-management-auth with endpoints-framework'
21-
)
22-
archivesBaseName = "endpoints-framework-auth"
17+
plugins {
18+
id("ut-publish")
19+
}
20+
21+
version = "1.0.15-SNAPSHOT"
22+
23+
// Set project-specific publishing properties
24+
publishing {
25+
publications {
26+
mavenJava(MavenPublication) {
27+
artifactId = "endpoints-framework-auth"
28+
from components.java
29+
pom {
30+
name.set("Endpoints API Management - Framework Auth Integration")
31+
description.set("Enables use of endpoints-management-auth with endpoints-framework")
32+
}
33+
}
34+
}
35+
}
2336

2437
dependencies {
2538
api group: "com.google.endpoints", name: "endpoints-framework", version: "${endpointsFrameworkVersion}"

0 commit comments

Comments
 (0)