Skip to content

Commit 9b96625

Browse files
committed
Add gradle-nexus publishing plugin
1 parent 929be22 commit 9b96625

File tree

1 file changed

+20
-62
lines changed

1 file changed

+20
-62
lines changed

build.gradle

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
id 'eclipse'
1313
id 'maven-publish'
1414
id 'signing'
15+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
1516
}
1617

1718
java {
@@ -52,9 +53,6 @@ def pomConfig = {
5253

5354
tasks.withType(Javadoc).all { enabled = false }
5455

55-
//Publishing tasks-
56-
//Maven Central Snapshot: publishSnapshotPublicationToMavenRepository
57-
//Maven Central Release: publishMavenCentralReleasePublicationToMaven2Repository
5856

5957
tasks.jar {
6058
manifest {
@@ -67,82 +65,42 @@ publishing {
6765

6866
publications {
6967

70-
maven(MavenPublication) {
71-
groupId project.property('mavenGroupId')
72-
artifactId project.property('mavenArtifactId')
73-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
74-
from components.java
75-
pom.withXml {
76-
def root = asNode()
77-
root.appendNode('name', 'Microsoft Graph SDK for Java')
78-
root.appendNode('url', 'https://github.com/microsoftgraph/msgraph-sdk-java')
79-
root.children().last() + pomConfig
80-
def pomFile = file("${project.buildDir}/libs/microsoft-graph.pom")
81-
writeTo(pomFile)
82-
}
83-
84-
}
85-
Snapshot(MavenPublication) {
68+
maven(MavenPublication) {
8669
customizePom(pom)
8770
groupId project.property('mavenGroupId')
8871
artifactId project.property('mavenArtifactId')
89-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
90-
from components.java
91-
pom.withXml {
92-
def pomFile = file("${project.buildDir}/generated-pom.xml")
93-
writeTo(pomFile)
94-
}
95-
}
96-
97-
mavenCentralRelease(MavenPublication) {
98-
customizePom(pom)
99-
groupId project.property('mavenGroupId')
100-
artifactId project.property('mavenArtifactId')
101-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
72+
version getVersionName()
10273
from components.java
10374
pom.withXml {
10475
def pomFile = file("${project.buildDir}/generated-pom.xml")
10576
writeTo(pomFile)
10677
}
10778
}
10879
}
109-
repositories {
110-
maven {
111-
url = 'https://oss.sonatype.org/content/repositories/snapshots'
112-
name = 'sonatypeSnapshot'
113-
114-
credentials {
115-
if (project.rootProject.file('local.properties').exists()) {
116-
Properties properties = new Properties()
117-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
118-
username = properties.getProperty('sonatypeUsername')
119-
password = properties.getProperty('sonatypePassword')
120-
}
121-
}
122-
}
123-
124-
maven {
125-
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
126-
name = 'sonatype'
127-
128-
credentials {
129-
if (project.rootProject.file('local.properties').exists()) {
130-
Properties properties = new Properties()
131-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
132-
username = properties.getProperty('sonatypeUsername')
133-
password = properties.getProperty('sonatypePassword')
134-
}
80+
}
81+
82+
nexusPublishing {
83+
repositories {
84+
sonatype {
85+
if (project.rootProject.file('local.properties').exists()) {
86+
Properties properties = new Properties()
87+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
88+
username = properties.getProperty('sonatypeUsername')
89+
password = properties.getProperty('sonatypePassword')
13590
}
13691
}
13792
}
13893
}
13994

95+
group = project.property('mavenGroupId')
96+
version = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
97+
14098
signing {
141-
sign publishing.publications.mavenCentralRelease
99+
sign publishing.publications.maven
142100
}
143101
tasks.withType(Sign)*.enabled = mavenCentralPublishingEnabled.toBoolean()
144102

145-
def fixAscNames = { name ->
103+
def fixAscNames = { name ->
146104
if(name.contains('pom')) {
147105
"${project.property('mavenArtifactId')}-${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}.pom.asc"
148106
} else {
@@ -161,7 +119,7 @@ def getVersionCode() {
161119
}
162120

163121
def getVersionName() {
164-
return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
122+
return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
165123
}
166124

167125
artifacts {
@@ -223,7 +181,7 @@ gradle.taskGraph.whenReady { taskGraph ->
223181
}
224182

225183
model {
226-
tasks.generatePomFileForMavenCentralReleasePublication {
184+
tasks.generatePomFileForMavenPublication {
227185
destination = file("${project.buildDir}/generated-pom.xml")
228186
}
229187
}

0 commit comments

Comments
 (0)