Skip to content

Commit dca5d64

Browse files
committed
Add gradle-nexus publishing plugin
1 parent 6747942 commit dca5d64

1 file changed

Lines changed: 20 additions & 64 deletions

File tree

build.gradle

Lines changed: 20 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ plugins {
1313
id 'eclipse'
1414
id 'maven-publish'
1515
id 'signing'
16+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
1617
}
1718

1819
java {
@@ -37,7 +38,6 @@ sourceSets {
3738
repositories {
3839
// You can declare any Maven/Ivy/file repository here.
3940
mavenCentral()
40-
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
4141
}
4242

4343
apply from: "gradle/dependencies.gradle"
@@ -54,10 +54,6 @@ def pomConfig = {
5454

5555
tasks.withType(Javadoc).all { enabled = false }
5656

57-
//Publishing tasks-
58-
//Maven Central Snapshot: publishSnapshotPublicationToMavenRepository
59-
//Maven Central Release: publishMavenCentralReleasePublicationToMaven2Repository
60-
6157
tasks.jar {
6258
manifest {
6359
attributes('Automatic-Module-Name': project.property('mavenGroupId'))
@@ -69,82 +65,42 @@ publishing {
6965

7066
publications {
7167

72-
maven(MavenPublication) {
73-
groupId project.property('mavenGroupId')
74-
artifactId project.property('mavenArtifactId')
75-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
76-
from components.java
77-
pom.withXml {
78-
def root = asNode()
79-
root.appendNode('name', 'Microsoft Graph Beta SDK for Java')
80-
root.appendNode('url', 'https://github.com/microsoftgraph/msgraph-beta-sdk-java')
81-
root.children().last() + pomConfig
82-
def pomFile = file("${project.buildDir}/libs/microsoft-graph-beta.pom")
83-
writeTo(pomFile)
84-
}
85-
86-
}
87-
Snapshot(MavenPublication) {
88-
customizePom(pom)
89-
groupId project.property('mavenGroupId')
90-
artifactId project.property('mavenArtifactId')
91-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
92-
from components.java
93-
pom.withXml {
94-
def pomFile = file("${project.buildDir}/generated-pom.xml")
95-
writeTo(pomFile)
96-
}
97-
}
98-
99-
mavenCentralRelease(MavenPublication) {
68+
maven(MavenPublication) {
10069
customizePom(pom)
10170
groupId project.property('mavenGroupId')
10271
artifactId project.property('mavenArtifactId')
103-
version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}"
72+
version getVersionName()
10473
from components.java
10574
pom.withXml {
10675
def pomFile = file("${project.buildDir}/generated-pom.xml")
10776
writeTo(pomFile)
10877
}
10978
}
11079
}
111-
repositories {
112-
maven {
113-
url = 'https://oss.sonatype.org/content/repositories/snapshots'
114-
name = 'sonatypeSnapshot'
115-
116-
credentials {
117-
if (project.rootProject.file('local.properties').exists()) {
118-
Properties properties = new Properties()
119-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
120-
username = properties.getProperty('sonatypeUsername')
121-
password = properties.getProperty('sonatypePassword')
122-
}
123-
}
124-
}
125-
126-
maven {
127-
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
128-
name = 'sonatype'
129-
130-
credentials {
131-
if (project.rootProject.file('local.properties').exists()) {
132-
Properties properties = new Properties()
133-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
134-
username = properties.getProperty('sonatypeUsername')
135-
password = properties.getProperty('sonatypePassword')
136-
}
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')
13790
}
13891
}
13992
}
14093
}
14194

95+
group = project.property('mavenGroupId')
96+
version = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
97+
14298
signing {
143-
sign publishing.publications.mavenCentralRelease
99+
sign publishing.publications.maven
144100
}
145101
tasks.withType(Sign)*.enabled = mavenCentralPublishingEnabled.toBoolean()
146102

147-
def fixAscNames = { name ->
103+
def fixAscNames = { name ->
148104
if(name.contains('pom')) {
149105
"${project.property('mavenArtifactId')}-${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}.pom.asc"
150106
} else {
@@ -163,7 +119,7 @@ def getVersionCode() {
163119
}
164120

165121
def getVersionName() {
166-
return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}"
122+
return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
167123
}
168124

169125
artifacts {
@@ -225,7 +181,7 @@ gradle.taskGraph.whenReady { taskGraph ->
225181
}
226182

227183
model {
228-
tasks.generatePomFileForMavenCentralReleasePublication {
184+
tasks.generatePomFileForMavenPublication {
229185
destination = file("${project.buildDir}/generated-pom.xml")
230186
}
231187
}

0 commit comments

Comments
 (0)