11import 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
25
36buildscript {
47 repositories {
@@ -10,7 +13,6 @@ buildscript {
1013plugins {
1114 id ' java'
1215 id ' jvm-test-suite'
13- id ' maven-publish'
1416 id " signing"
1517 id " org.openapi.generator" version libs. versions. openapi. generator
1618 id " com.diffplug.spotless" version libs. versions. spotless
@@ -19,6 +21,7 @@ plugins {
1921 id " com.github.spotbugs" version libs. versions. spotbugs
2022 id " org.owasp.dependencycheck" version libs. versions. depcheck
2123 id ' me.champeau.jmh' version ' 0.6.8' // Added JMH plugin
24+ id " com.vanniktech.maven.publish" version " 0.33.0"
2225}
2326
2427
@@ -34,8 +37,6 @@ allprojects {
3437
3538 java {
3639 sourceCompatibility = JavaVersion . VERSION_1_8
37- withJavadocJar()
38- withSourcesJar()
3940 }
4041
4142 apply plugin : ' java-library'
@@ -98,16 +99,6 @@ tasks.register('generateVersion', Copy) {
9899 expand tokens
99100}
100101
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-
111102testing {
112103 suites {
113104 test {
@@ -152,94 +143,91 @@ testing {
152143 }
153144}
154145
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+ }
171178
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+ }
176184
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/"
183192 }
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/"
189199 }
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/"
234227 }
235228 }
236- }
237- }
238-
239- signing {
240- required { gradle. taskGraph. hasTask(" publish" ) }
241229
242- sign publishing . publications . mavenJava
230+ }
243231}
244232
245233spotless {
@@ -261,8 +249,6 @@ dependencyCheck {
261249compileJava. dependsOn tasks. openApiGenerate
262250compileJava. dependsOn generateVersion
263251compileJava. dependsOn spotlessApply
264- sourcesJar. dependsOn tasks. openApiGenerate
265- sourcesJar. dependsOn generateVersion
266252jacocoTestReport. dependsOn test
267253spotbugsTest. enabled = false
268254spotbugsMain. enabled = false
@@ -272,3 +258,17 @@ sourceSets.main.java.srcDirs += [ "$buildDir/generated/src/main/java", "$buildDi
272258tasks. withType(Javadoc ). configureEach {
273259 options. addStringOption(' Xdoclint:none' , ' -quiet' )
274260}
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