Skip to content

Commit 3b317f4

Browse files
committed
Add gradle-nexus publishing plugin and config
1 parent 5547b34 commit 3b317f4

File tree

1 file changed

+18
-62
lines changed

1 file changed

+18
-62
lines changed

build.gradle

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id 'jacoco'
88
id 'com.github.spotbugs' version '6.0.20'
99
id "org.sonarqube" version "5.1.0.4882"
10+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
1011
}
1112

1213
java {
@@ -90,10 +91,6 @@ sonarqube {
9091
}
9192
}
9293

93-
//Publishing tasks-
94-
//Maven Central Snapshot: publishSnapshotPublicationToMavenRepository
95-
//Maven Central Release: publishMavenCentralReleasePublicationToMaven2Repository
96-
//Bintray Snapshot: publishSnapshotPublicationToMaven3Repository
9794

9895
tasks.jar {
9996
manifest {
@@ -104,79 +101,38 @@ tasks.jar {
104101
publishing {
105102

106103
publications {
107-
108-
maven(MavenPublication) {
109-
groupId project.property('mavenGroupId')
110-
artifactId project.property('mavenArtifactId')
111-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
112-
from components.java
113-
pom.withXml {
114-
def root = asNode()
115-
root.appendNode('name', 'Microsoft Graph Core SDK for Java')
116-
root.appendNode('url', 'https://github.com/microsoftgraph/msgraph-sdk-java-core')
117-
root.children().last() + pomConfig
118-
def pomFile = file("${project.buildDir}/libs/microsoft-graph-core.pom")
119-
writeTo(pomFile)
120-
}
121-
122-
}
123-
Snapshot(MavenPublication) {
124-
customizePom(pom)
125-
groupId project.property('mavenGroupId')
126-
artifactId project.property('mavenArtifactId')
127-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
128-
from components.java
129-
pom.withXml {
130-
def pomFile = file("${project.buildDir}/generated-pom.xml")
131-
writeTo(pomFile)
132-
}
133-
}
134-
135-
mavenCentralRelease(MavenPublication) {
104+
maven(MavenPublication) {
136105
customizePom(pom)
137106
groupId project.property('mavenGroupId')
138107
artifactId project.property('mavenArtifactId')
139-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
108+
version getVersionName()
140109
from components.java
141110
pom.withXml {
142111
def pomFile = file("${project.buildDir}/generated-pom.xml")
143112
writeTo(pomFile)
144113
}
145114
}
146115
}
147-
repositories {
148-
maven {
149-
url = 'https://oss.sonatype.org/content/repositories/snapshots'
150-
name = 'sonatypeSnapshot'
151-
152-
credentials {
153-
if (project.rootProject.file('local.properties').exists()) {
154-
Properties properties = new Properties()
155-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
156-
username = properties.getProperty('sonatypeUsername')
157-
password = properties.getProperty('sonatypePassword')
158-
}
159-
}
160-
}
161-
162-
maven {
163-
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
164-
name = 'sonatype'
116+
}
165117

166-
credentials {
167-
if (project.rootProject.file('local.properties').exists()) {
168-
Properties properties = new Properties()
169-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
170-
username = properties.getProperty('sonatypeUsername')
171-
password = properties.getProperty('sonatypePassword')
172-
}
118+
nexusPublishing {
119+
repositories {
120+
sonatype {
121+
if (project.rootProject.file('local.properties').exists()) {
122+
Properties properties = new Properties()
123+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
124+
username = properties.getProperty('sonatypeUsername')
125+
password = properties.getProperty('sonatypePassword')
173126
}
174127
}
175128
}
176129
}
177130

131+
group = project.property('mavenGroupId')
132+
version = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
133+
178134
signing {
179-
sign publishing.publications.mavenCentralRelease
135+
sign publishing.publications.maven
180136
}
181137
tasks.withType(Sign)*.enabled = mavenCentralPublishingEnabled.toBoolean()
182138

@@ -199,7 +155,7 @@ def getVersionCode() {
199155
}
200156

201157
def getVersionName() {
202-
return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
158+
return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
203159
}
204160

205161
artifacts {
@@ -261,7 +217,7 @@ gradle.taskGraph.whenReady { taskGraph ->
261217
}
262218

263219
model {
264-
tasks.generatePomFileForMavenCentralReleasePublication {
220+
tasks.generatePomFileForMavenPublication {
265221
destination = file("${project.buildDir}/generated-pom.xml")
266222
}
267223
}

0 commit comments

Comments
 (0)