Skip to content

Commit 0f80c0a

Browse files
author
Nakul Sabharwal
committed
restructured gradle publishing tasks for release automation pipeline.
1 parent ed840d3 commit 0f80c0a

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

build.gradle

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,29 @@ publishing {
7272
}
7373

7474
}
75-
mavenJava(MavenPublication) {
75+
mavenCentralSnapshot(MavenPublication) {
7676
customizePom(pom)
7777
groupId 'com.microsoft.graph'
7878
artifactId 'microsoft-graph'
79-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
79+
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
80+
from components.java
81+
pom.withXml {
82+
def pomFile = file("${project.buildDir}/generated-pom.xml")
83+
writeTo(pomFile)
84+
}
85+
artifact(sourceJar) {
86+
classifier = 'sources'
87+
}
88+
artifact(javadocJar) {
89+
classifier = 'javadoc'
90+
}
91+
}
92+
93+
mavenCentralRelease(MavenPublication) {
94+
customizePom(pom)
95+
groupId 'com.microsoft.graph'
96+
artifactId 'microsoft-graph'
97+
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
8098
from components.java
8199
pom.withXml {
82100
def pomFile = file("${project.buildDir}/generated-pom.xml")
@@ -109,10 +127,38 @@ publishing {
109127
}
110128
repositories {
111129
maven {
112-
url = project.property('mavenCentralUploadUrl')
130+
url = project.property('mavenCentralSnapshotUrl')
131+
113132
credentials {
114-
username = project.property('sonatypeUsername')
115-
password = project.property('sonatypePassword')
133+
if (project.rootProject.file('local.properties').exists()) {
134+
135+
Properties properties = new Properties()
136+
137+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
138+
139+
username = properties.getProperty('sonatypeUsername')
140+
141+
password = properties.getProperty('sonatypePassword')
142+
143+
}
144+
}
145+
}
146+
147+
maven {
148+
url = project.property('mavenCentralReleaseUrl')
149+
150+
credentials {
151+
if (project.rootProject.file('local.properties').exists()) {
152+
153+
Properties properties = new Properties()
154+
155+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
156+
157+
username = properties.getProperty('sonatypeUsername')
158+
159+
password = properties.getProperty('sonatypePassword')
160+
161+
}
116162
}
117163
}
118164
}
@@ -170,6 +216,8 @@ uploadArchives {
170216
}
171217

172218
repository (url: project.mavenRepoUrl) {
219+
220+
url = url + "/" + getVersionName()
173221

174222
authentication(
175223

@@ -246,14 +294,26 @@ def customizePom(pom) {
246294
}
247295
}
248296

297+
gradle.taskGraph.whenReady { taskGraph ->
298+
if (taskGraph.allTasks.any { it instanceof Sign }) {
299+
if (project.rootProject.file('local.properties').exists()) {
300+
Properties properties = new Properties()
301+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
302+
allprojects { ext."signing.keyId" = properties.getProperty('signing.keyId') }
303+
allprojects { ext."signing.secretKeyRingFile" = properties.getProperty('signing.secretKeyRingFile') }
304+
allprojects { ext."signing.password" = properties.getProperty('signing.password') }
305+
}
306+
}
307+
}
308+
249309
model {
250-
tasks.generatePomFileForMavenJavaPublication {
310+
tasks.generatePomFileForMavenReleasePublication {
251311
destination = file("$buildDir/generated-pom.xml")
252312
}
253-
tasks.publishMavenJavaPublicationToMavenLocal {
313+
tasks.publishMavenReleasePublicationToMavenLocal {
254314
dependsOn project.tasks.signArchives
255315
}
256-
tasks.publishMavenJavaPublicationToMavenRepository {
316+
tasks.publishMavenReleasePublicationToMaven2Repository {
257317
dependsOn project.tasks.signArchives
258318
}
259319
}

gradle.properties

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ ClientId="CLIENT_ID"
3838
Username="USERNAME"
3939
Password="PASSWORD"
4040

41-
#enter below credentials and enable mavenCentralPublishingEnabled to publish to maven central
42-
signing.keyId="keyId"
43-
signing.secretKeyRingFile="fileLocation"
44-
signing.password="passphrase"
45-
sonatypeUsername="USERNAME"
46-
sonatypePassword="PASSWORD"
47-
mavenCentralUploadUrl=https://oss.sonatype.org/content/repositories/snapshots
41+
#enable mavenCentralPublishingEnabled to publish to maven central
42+
mavenCentralSnapshotUrl=https://oss.sonatype.org/content/repositories/snapshots
43+
mavenCentralReleaseUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2
44+
mavenCentralSnapshotArtifactSuffix = -SNAPSHOT
4845
mavenCentralPublishingEnabled=false

0 commit comments

Comments
 (0)