1
1
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2
+ import com.vanniktech.maven.publish.SonatypeHost
3
+ import com.vanniktech.maven.publish.JavaLibrary
4
+ import com.vanniktech.maven.publish.JavadocJar
2
5
3
6
buildscript {
4
7
repositories {
@@ -10,7 +13,6 @@ buildscript {
10
13
plugins {
11
14
id ' java'
12
15
id ' jvm-test-suite'
13
- id ' maven-publish'
14
16
id " signing"
15
17
id " org.openapi.generator" version libs. versions. openapi. generator
16
18
id " com.diffplug.spotless" version libs. versions. spotless
@@ -19,6 +21,7 @@ plugins {
19
21
id " com.github.spotbugs" version libs. versions. spotbugs
20
22
id " org.owasp.dependencycheck" version libs. versions. depcheck
21
23
id ' me.champeau.jmh' version ' 0.6.8' // Added JMH plugin
24
+ id " com.vanniktech.maven.publish" version " 0.33.0"
22
25
}
23
26
24
27
@@ -34,8 +37,6 @@ allprojects {
34
37
35
38
java {
36
39
sourceCompatibility = JavaVersion . VERSION_1_8
37
- withJavadocJar()
38
- withSourcesJar()
39
40
}
40
41
41
42
apply plugin : ' java-library'
@@ -98,16 +99,6 @@ tasks.register('generateVersion', Copy) {
98
99
expand tokens
99
100
}
100
101
101
- // From https://stackoverflow.com/a/74205283
102
- tasks. register(" copyPomToRoot" ) {
103
- def publication = publishing. publications. mavenJava
104
- def generatePom = tasks. named(" generatePomFileFor${ publication.name.capitalize()} Publication" )
105
- dependsOn(generatePom)
106
- def output = rootProject. file(" ${ publication.artifactId} -${ publication.version} .pom" )
107
- outputs. file(output)
108
- doLast { output. bytes = generatePom. get(). destination. bytes }
109
- }
110
-
111
102
testing {
112
103
suites {
113
104
test {
@@ -152,94 +143,91 @@ testing {
152
143
}
153
144
}
154
145
155
- publishing {
156
- repositories {
157
- maven {
158
- credentials {
159
- username System . getenv(" MAVEN_USERNAME" ) != null ? System . getenv(" MAVEN_USERNAME" ) : " "
160
- password System . getenv(" MAVEN_PASSWORD" ) != null ? System . getenv(" MAVEN_PASSWORD" ) : " "
161
- }
162
-
163
- def sonatypeSnapshotRepo = " https://s01.oss.sonatype.org/content/repositories/snapshots/"
164
- def sonatypeStagingRepo= " https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
165
- url = version. endsWith(' SNAPSHOT' ) ? sonatypeSnapshotRepo : sonatypeStagingRepo
166
- }
167
- }
168
-
169
- publications. create(" mavenJava" , MavenPublication ) {
170
- from components. java
146
+ mavenPublishing {
147
+
148
+ // To publish, make sure the following env vars are set
149
+ //
150
+ // ORG_GRADLE_PROJECT_mavenCentralUsername
151
+ // ORG_GRADLE_PROJECT_mavenCentralPassword
152
+ //
153
+ // To sign, make sure the following properties are set
154
+ //
155
+ // signing.secretKeyRingFile=(keyring location - e.g. output of `gpg --no-default-keyring --keyring secring.gpg --export-secret-keys <LONGID> >/tmp/keyring.gpg`)
156
+ // signing.password=(****)
157
+ // signing.keyId=(8 digit keyid)
158
+ //
159
+ // Also make sure that corresponding public key has been published to hkp://keys.openpgp.org, hkp://pgp.mit.edu, etc.
160
+
161
+ publishToMavenCentral(SonatypeHost . CENTRAL_PORTAL )
162
+ signAllPublications()
163
+
164
+ configure(new JavaLibrary (new JavadocJar.Javadoc (), true ))
165
+
166
+ pom {
167
+ description = project. description
168
+ name = project. name
169
+ url = " https://github.com/harness/ff-java-server-sdk"
170
+
171
+ licenses {
172
+ license {
173
+ name = " Apache License, Version 2.0"
174
+ url = " http://www.apache.org/licenses/LICENSE-2.0.txt"
175
+ distribution = " repo"
176
+ }
177
+ }
171
178
172
- pom {
173
- description = project. description
174
- name = project. name
175
- url = " https://github.com/harness/ff-java-server-sdk"
179
+ scm {
180
+ developerConnection = " scm:git:ssh://https://github.com/harness/ff-java-server-sdk.git"
181
+ connection = " scm:git:ssh://https://github.com/harness/ff-java-server-sdk.git"
182
+ url = " https://github.com/drone/ff-java-server-sdk"
183
+ }
176
184
177
- licenses {
178
- license {
179
- name = " Apache License, Version 2.0"
180
- url = " http://www.apache.org/licenses/LICENSE-2.0.txt"
181
- distribution = " repo"
182
- }
185
+ developers {
186
+ developer {
187
+ id = " andybharness"
188
+ name = " Andrew Bell"
189
+
190
+ organization = " Harness Inc"
191
+ organizationUrl = " https://www.harness.io/"
183
192
}
184
-
185
- scm {
186
- developerConnection = " scm:git:ssh://https://github.com/harness/ff-java-server-sdk.git"
187
- connection = " scm:git:ssh://https://github.com/harness/ff-java-server-sdk.git"
188
- url = " https://github.com/drone/ff-java-server-sdk"
193
+ developer {
194
+ id = " davejohnston"
195
+ name = " Dave Johnston"
196
+
197
+ organization = " Harness Inc"
198
+ organizationUrl = " https://www.harness.io/"
189
199
}
190
-
191
- developers {
192
- developer {
193
- id = " andybharness"
194
- name = " Andrew Bell"
195
-
196
- organization = " Harness Inc"
197
- organizationUrl = " https://www.harness.io/"
198
- }
199
- developer {
200
- id = " davejohnston"
201
- name = " Dave Johnston"
202
-
203
- organization = " Harness Inc"
204
- organizationUrl = " https://www.harness.io/"
205
- }
206
- developer {
207
- id = " enver-bisevac"
208
- name = " Enver Bisevac"
209
-
210
- organization = " Harness Inc"
211
- organizationUrl = " https://www.harness.io/"
212
- }
213
- developer {
214
- id = " rushabh-harness"
215
- name = " Rushabh Shah"
216
-
217
- organization = " Harness Inc"
218
- organizationUrl = " https://www.harness.io/"
219
- }
220
- developer {
221
- id = " hannah-tang"
222
- name = " Hannah Tang"
223
-
224
- organization = " Harness Inc"
225
- organizationUrl = " https://www.harness.io/"
226
- }
227
- developer {
228
- id = " subiradhikari"
229
- name = " Subir Adhikari"
230
-
231
- organization = " Harness Inc"
232
- organizationUrl = " https://www.harness.io/"
233
- }
200
+ developer {
201
+ id = " enver-bisevac"
202
+ name = " Enver Bisevac"
203
+
204
+ organization = " Harness Inc"
205
+ organizationUrl = " https://www.harness.io/"
206
+ }
207
+ developer {
208
+ id = " rushabh-harness"
209
+ name = " Rushabh Shah"
210
+
211
+ organization = " Harness Inc"
212
+ organizationUrl = " https://www.harness.io/"
213
+ }
214
+ developer {
215
+ id = " hannah-tang"
216
+ name = " Hannah Tang"
217
+
218
+ organization = " Harness Inc"
219
+ organizationUrl = " https://www.harness.io/"
220
+ }
221
+ developer {
222
+ id = " subiradhikari"
223
+ name = " Subir Adhikari"
224
+
225
+ organization = " Harness Inc"
226
+ organizationUrl = " https://www.harness.io/"
234
227
}
235
228
}
236
- }
237
- }
238
-
239
- signing {
240
- required { gradle. taskGraph. hasTask(" publish" ) }
241
229
242
- sign publishing . publications . mavenJava
230
+ }
243
231
}
244
232
245
233
spotless {
@@ -261,8 +249,6 @@ dependencyCheck {
261
249
compileJava. dependsOn tasks. openApiGenerate
262
250
compileJava. dependsOn generateVersion
263
251
compileJava. dependsOn spotlessApply
264
- sourcesJar. dependsOn tasks. openApiGenerate
265
- sourcesJar. dependsOn generateVersion
266
252
jacocoTestReport. dependsOn test
267
253
spotbugsTest. enabled = false
268
254
spotbugsMain. enabled = false
@@ -272,3 +258,17 @@ sourceSets.main.java.srcDirs += [ "$buildDir/generated/src/main/java", "$buildDi
272
258
tasks. withType(Javadoc ). configureEach {
273
259
options. addStringOption(' Xdoclint:none' , ' -quiet' )
274
260
}
261
+
262
+ tasks. named(" sourcesJar" ) {
263
+ dependsOn(tasks. named(" generateVersion" ))
264
+ }
265
+
266
+ wrapper {
267
+ gradleVersion = ' 8.14.2'
268
+ distributionType = Wrapper.DistributionType . ALL
269
+ }
270
+
271
+ tasks. named(" generatePomFileForMavenPublication" ). configure {
272
+ def publication = publishing. publications. maven
273
+ destination = rootProject. file(" ${ publication.artifactId} -${ publication.version} .pom" )
274
+ }
0 commit comments