Skip to content

Commit 7b35598

Browse files
committed
change to maven_publish plugin to handle artifact publish
Signed-off-by: Leo Ma <[email protected]>
1 parent fa055bb commit 7b35598

File tree

2 files changed

+84
-112
lines changed

2 files changed

+84
-112
lines changed

build.gradle

Lines changed: 82 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
plugins {
2+
id 'java'
3+
id 'com.github.sherter.google-java-format' version '0.8'
4+
id 'signing'
5+
id 'maven-publish'
6+
id 'io.codearte.nexus-staging' version '0.21.2'
7+
}
8+
19
group 'com.cisco.trex'
210

311
ext {
@@ -15,25 +23,9 @@ ext {
1523
develop2Mail = "[email protected]"
1624
}
1725

18-
apply plugin: 'java'
19-
apply plugin: 'maven'
20-
apply plugin: 'com.github.sherter.google-java-format'
21-
apply plugin: 'signing'
22-
2326
sourceCompatibility = 1.8
2427
targetCompatibility = 1.8
2528

26-
buildscript {
27-
repositories {
28-
maven {
29-
url "https://plugins.gradle.org/m2/"
30-
}
31-
}
32-
dependencies {
33-
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
34-
}
35-
}
36-
3729
repositories {
3830
mavenCentral()
3931
}
@@ -65,49 +57,6 @@ dependencies {
6557
}
6658
}
6759

68-
task writePom {
69-
doLast {
70-
pom {
71-
project {
72-
name projectName
73-
packaging 'jar'
74-
description projectDescription
75-
url projectUrl
76-
licenses {
77-
license {
78-
name licenseName
79-
url licenseUrl
80-
}
81-
}
82-
83-
scm {
84-
connection scmConnection
85-
developerConnection scmDeveloperConnection
86-
url scmUrl
87-
}
88-
89-
developers {
90-
developer {
91-
name develop1Name
92-
email develop1Mail
93-
}
94-
developer {
95-
name develop2Name
96-
email develop2Mail
97-
}
98-
}
99-
}
100-
}.writeTo("pom.xml")
101-
}
102-
}
103-
104-
jar {
105-
dependsOn writePom
106-
into("META-INF/maven/$project.group/$project.name") {
107-
from("pom.xml")
108-
}
109-
}
110-
11160
task javadocJar(type: Jar) {
11261
classifier = 'javadoc'
11362
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
@@ -119,21 +68,10 @@ task sourcesJar(type: Jar) {
11968
from sourceSets.main.allSource
12069
}
12170

122-
task jarWithDependencies(type: Jar) {
123-
dependsOn writePom
124-
baseName = project.name + '-with-dependencies'
125-
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
126-
with jar
127-
}
128-
12971
artifacts {
13072
archives javadocJar, sourcesJar
13173
}
13274

133-
signing {
134-
sign configurations.archives
135-
}
136-
13775
test {
13876
testLogging {
13977
events "passed", "skipped" , "failed"
@@ -156,47 +94,81 @@ task e2eTest(type: Test) {
15694
}
15795
}
15896

159-
uploadArchives {
160-
repositories {
161-
mavenDeployer {
162-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
163-
164-
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
165-
authentication(userName: ossrhUsername, password: ossrhPassword)
166-
}
167-
168-
pom.project {
169-
name projectName
170-
packaging 'jar'
171-
description projectDescription
172-
url projectUrl
173-
licenses {
174-
license {
175-
name licenseName
176-
url licenseUrl
177-
}
178-
}
179-
180-
scm {
181-
connection scmConnection
182-
developerConnection scmDeveloperConnection
183-
url scmUrl
184-
}
97+
publishing {
98+
publications {
99+
mavenJava(MavenPublication) {
100+
artifactId archivesBaseName
101+
from components.java
102+
artifact sourcesJar
103+
artifact javadocJar
104+
pom {
105+
name = projectName
106+
packaging = 'jar'
107+
description = projectDescription
108+
url = projectUrl
185109

186-
developers {
187-
developer {
188-
name develop1Name
189-
email develop1Mail
190-
}
191-
developer {
192-
name develop2Name
193-
email develop2Mail
194-
}
195-
}
196-
}
110+
licenses {
111+
license {
112+
name = licenseName
113+
url = licenseUrl
114+
}
115+
}
116+
117+
scm {
118+
connection = scmConnection
119+
developerConnection = scmDeveloperConnection
120+
url = scmUrl
121+
}
122+
123+
developers {
124+
developer {
125+
name = develop1Name
126+
email = develop1Mail
127+
}
128+
developer {
129+
name = develop2Name
130+
email = develop2Mail
131+
}
132+
}
133+
}
134+
}
135+
}
136+
137+
repositories {
138+
maven {
139+
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
140+
credentials {
141+
username project.findProperty('nexusUsername') ?: 'secured'
142+
password project.findProperty('nexusPassword') ?: 'secured'
143+
}
144+
}
145+
}
146+
147+
}
148+
149+
signing {
150+
sign publishing.publications.mavenJava
151+
}
152+
153+
generatePomFileForMavenJavaPublication {
154+
destination = file("pom.xml")
155+
}
156+
157+
jar {
158+
dependsOn generatePomFileForMavenJavaPublication
159+
into("META-INF/maven/$project.group/$project.name") {
160+
from("pom.xml")
197161
}
198-
}
199162
}
200163

201-
//disable signArchives in build due to no GPG key properties is configured in gradle.properties
202-
signArchives.enabled = false
164+
task jarWithDependencies(type: Jar) {
165+
dependsOn generatePomFileForMavenJavaPublication
166+
baseName = project.name + '-with-dependencies'
167+
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
168+
with jar
169+
}
170+
171+
nexusStaging {
172+
numberOfRetries = 40
173+
delayBetweenRetriesInMillis = 5000
174+
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ signing.password=YourPublicKeyPassword
99
signing.secretKeyRingFile=PathToYourKeyRingFile
1010

1111
# ossrh user information
12-
ossrhUsername=your-jira-id
13-
ossrhPassword=your-jira-password
12+
nexusUsername=your-jira-id
13+
nexusPassword=your-jira-password

0 commit comments

Comments
 (0)