From 971c7786f44ca712b8aa07ff467db06ec907e0c8 Mon Sep 17 00:00:00 2001 From: Wang Xia <83057695+wang-x-xia@users.noreply.github.com> Date: Thu, 14 Oct 2021 16:29:41 +0800 Subject: [PATCH 1/5] Add a bundle module for bundled client. --- build.gradle | 19 ++++-- bundle/build.gradle | 125 +++++++++++++++++++++++++++++++++++++++ geo-pin-cli/build.gradle | 2 +- settings.gradle | 2 + 4 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 bundle/build.gradle diff --git a/build.gradle b/build.gradle index 119910ed..9a7aeffe 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,7 @@ plugins { id 'maven' id 'org.ajoberstar.git-publish' version '3.0.0' id 'nebula.release' version '15.2.0' + id 'com.github.johnrengelman.shadow' version '5.2.0' apply false } group 'com.emc.ecs' @@ -241,8 +242,8 @@ clean { // allow typing in credentials // note: this only works when run without the Gradle daemon (--no-daemon) -gradle.taskGraph.whenReady { taskGraph -> - if (taskGraph.hasTask(':uploadJars')) { +task setupPublish { + doLast { if (!rootProject.hasProperty('signingSecretKeyRingFile')) rootProject.ext.signingSecretKeyRingFile = new String(System.console().readLine('\nSecret key ring file: ')) if (!rootProject.hasProperty('signingKeyId')) @@ -259,7 +260,14 @@ gradle.taskGraph.whenReady { taskGraph -> uploadJars.repositories.mavenDeployer.repository.authentication.userName = rootProject.ext.sonatypeUser uploadJars.repositories.mavenDeployer.repository.authentication.password = rootProject.ext.sonatypePass } - if (taskGraph.hasTask(':gitPublishPush') || taskGraph.hasTask(':release')) { +} + +tasks.uploadJars.dependsOn(tasks.setupPublish) + +// allow typing in credentials +// note: this only works when run without the Gradle daemon (--no-daemon) +task setupRelease { + doLast { if (!rootProject.hasProperty('gitUsername')) rootProject.ext.gitUsername = new String(System.console().readLine('\nGit username: ')) if (!rootProject.hasProperty('gitPassword')) @@ -267,4 +275,7 @@ gradle.taskGraph.whenReady { taskGraph -> System.setProperty('org.ajoberstar.grgit.auth.username', rootProject.ext.gitUsername) System.setProperty('org.ajoberstar.grgit.auth.password', rootProject.ext.gitPassword) } -} \ No newline at end of file +} + +tasks.gitPublishPush.dependsOn(tasks.setupPublish) +tasks.release.dependsOn(tasks.setupPublish) \ No newline at end of file diff --git a/bundle/build.gradle b/bundle/build.gradle new file mode 100644 index 00000000..f20d1a3d --- /dev/null +++ b/bundle/build.gradle @@ -0,0 +1,125 @@ +plugins { + id 'java' + id 'signing' + id 'maven-publish' + id 'com.github.johnrengelman.shadow' +} + +group = rootProject.group +description = rootProject.description + +repositories { + mavenCentral() + mavenLocal() +} + +dependencies { + // Let user use this dependencies + shadow 'org.slf4j:slf4j-api:1.7.32' + shadow 'commons-logging:commons-logging:1.2' + implementation(rootProject) { + // used for Jackson + exclude group: 'jakarta.xml.bind' + exclude group: 'jakarta.activation' + // used for jersey-json + exclude group: 'javax.xml.bind' + exclude group: 'com.sun.xml.bind' + exclude group: 'javax.activation' + // log + exclude group: 'org.slf4j' + exclude group: 'commons-logging::' + } +} + +shadowJar { + archiveClassifier = null + def r = { String p -> relocate(p, 'com.emc.object.shadow.' + p) } + r 'com.fasterxml' + r 'com.sun.jersey' + r 'com.sun.ws.rs' + r 'com.sun.istack' + r 'javax.ws.rs' + r 'org.apache.commons.codec' + r 'org.apache.http' + r 'org.codehaus.jettison' + r 'org.dom4j' + r 'SevenZip' + + mergeServiceFiles() +} + +jar { + enabled = false +} + +publishing { + publications { + mavenJava(MavenPublication) { p -> + project.shadow.component(p) + pom { + name = project.name + description = project.description + url = githubProjectUrl + + scm { + url = githubProjectUrl + connection = githubScmUrl + developerConnection = githubScmUrl + } + + licenses { + license { + name = licenseName + url = licenseUrl + distribution = 'repo' + } + } + + developers { + developer { + id = 'EMCECS' + name = 'Dell EMC ECS' + } + } + } + } + } + repositories { + maven { + name = 'Sonatype' + url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' + credentials { + username = '' + password = '' + } + } + } +} + +signing { + required { gradle.taskGraph.hasTask(':setupPublish') } + sign publishing.publications.mavenJava +} + +/** + * The unit test task is to verify bundled jar. + */ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +task shadowTestJar(type: ShadowJar) { + archiveClassifier = "tests" + from rootProject.sourceSets.test.output + configurations = [] + relocators = shadowJar.relocators +} + +test { + // add original unit tests + testClassesDirs = rootProject.test.testClassesDirs + // shadow test files + classpath = tasks.shadowTestJar.outputs.files + + // original runtime class path without shadowed dependencies + (rootProject.configurations.testRuntimeClasspath - shadowJar.includedDependencies) + + // shadow jar + shadowJar.outputs.files +} \ No newline at end of file diff --git a/geo-pin-cli/build.gradle b/geo-pin-cli/build.gradle index df5efe28..54f53aa9 100644 --- a/geo-pin-cli/build.gradle +++ b/geo-pin-cli/build.gradle @@ -27,7 +27,7 @@ plugins { id 'java' id 'application' - id 'com.github.johnrengelman.shadow' version '5.2.0' + id 'com.github.johnrengelman.shadow' } group 'com.emc.ecs' diff --git a/settings.gradle b/settings.gradle index cd9eb98c..3def42ae 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ rootProject.name = 'object-client' include 'geo-pin-cli' +include 'bundle' +project(":bundle").name = 'object-client-bundle' From 481cb5c0904fbca2cb7a59519ac3feca72140f83 Mon Sep 17 00:00:00 2001 From: Wang Xia <83057695+wang-x-xia@users.noreply.github.com> Date: Thu, 14 Oct 2021 17:00:14 +0800 Subject: [PATCH 2/5] Change the publishing tasks of bundle module. --- build.gradle | 3 ++- bundle/build.gradle | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9a7aeffe..76e96111 100644 --- a/build.gradle +++ b/build.gradle @@ -278,4 +278,5 @@ task setupRelease { } tasks.gitPublishPush.dependsOn(tasks.setupPublish) -tasks.release.dependsOn(tasks.setupPublish) \ No newline at end of file +tasks.release.dependsOn(tasks.setupRelease) +tasks.gitPublishPush.dependsOn(tasks.setupRelease) diff --git a/bundle/build.gradle b/bundle/build.gradle index f20d1a3d..cfbf8442 100644 --- a/bundle/build.gradle +++ b/bundle/build.gradle @@ -97,10 +97,25 @@ publishing { } signing { - required { gradle.taskGraph.hasTask(':setupPublish') } + required { gradle.taskGraph.hasTask(':object-client-bundle:setupPublish') } sign publishing.publications.mavenJava } +task setupPublish(dependsOn: ":setupPublish") { + doLast { + ext.'signing.keyId' = rootProject.ext.signingKeyId + ext.'signing.secretKeyRingFile' = rootProject.ext.signingSecretKeyRingFile + ext.'signing.password' = rootProject.ext.signingPass + publishing.repositories.findByName("Sonatype") { + credentials { + username = rootProject.ext.sonatypeUser + password = rootProject.ext.sonatypePass + } + } + } +} +tasks.publishAllPublicationsToSonatypeRepository.dependsOn(tasks.setupPublish) + /** * The unit test task is to verify bundled jar. */ From aaede9f65569384a64a745713097a977708390cc Mon Sep 17 00:00:00 2001 From: Wang Xia <83057695+wang-x-xia@users.noreply.github.com> Date: Thu, 14 Oct 2021 17:01:34 +0800 Subject: [PATCH 3/5] Fix bug. --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 76e96111..d6727a2a 100644 --- a/build.gradle +++ b/build.gradle @@ -277,6 +277,5 @@ task setupRelease { } } -tasks.gitPublishPush.dependsOn(tasks.setupPublish) -tasks.release.dependsOn(tasks.setupRelease) tasks.gitPublishPush.dependsOn(tasks.setupRelease) +tasks.release.dependsOn(tasks.setupRelease) From 5258ce52172bfc1929a2c85451e42cef54e1ccf5 Mon Sep 17 00:00:00 2001 From: Wang Xia <83057695+wang-x-xia@users.noreply.github.com> Date: Thu, 14 Oct 2021 17:12:16 +0800 Subject: [PATCH 4/5] Fix group of log libraries. --- bundle/build.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bundle/build.gradle b/bundle/build.gradle index cfbf8442..fcada3e7 100644 --- a/bundle/build.gradle +++ b/bundle/build.gradle @@ -27,7 +27,7 @@ dependencies { exclude group: 'javax.activation' // log exclude group: 'org.slf4j' - exclude group: 'commons-logging::' + exclude group: 'commons-logging' } } @@ -46,6 +46,10 @@ shadowJar { r 'SevenZip' mergeServiceFiles() + + doLast { + println("All ${includedDependencies.files}") + } } jar { From bac81283187191e572d41c1d6a5a5d37829575a0 Mon Sep 17 00:00:00 2001 From: Wang Xia <83057695+wang-x-xia@users.noreply.github.com> Date: Wed, 20 Oct 2021 17:40:32 +0800 Subject: [PATCH 5/5] 1. Revert changes in root build.gradle. 2. Simplify publish setup in bundle module. --- build.gradle | 18 ++++-------------- bundle/build.gradle | 27 ++++----------------------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/build.gradle b/build.gradle index d6727a2a..c53b6648 100644 --- a/build.gradle +++ b/build.gradle @@ -242,8 +242,8 @@ clean { // allow typing in credentials // note: this only works when run without the Gradle daemon (--no-daemon) -task setupPublish { - doLast { +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.hasTask(':uploadJars')) { if (!rootProject.hasProperty('signingSecretKeyRingFile')) rootProject.ext.signingSecretKeyRingFile = new String(System.console().readLine('\nSecret key ring file: ')) if (!rootProject.hasProperty('signingKeyId')) @@ -260,14 +260,7 @@ task setupPublish { uploadJars.repositories.mavenDeployer.repository.authentication.userName = rootProject.ext.sonatypeUser uploadJars.repositories.mavenDeployer.repository.authentication.password = rootProject.ext.sonatypePass } -} - -tasks.uploadJars.dependsOn(tasks.setupPublish) - -// allow typing in credentials -// note: this only works when run without the Gradle daemon (--no-daemon) -task setupRelease { - doLast { + if (taskGraph.hasTask(':gitPublishPush') || taskGraph.hasTask(':release')) { if (!rootProject.hasProperty('gitUsername')) rootProject.ext.gitUsername = new String(System.console().readLine('\nGit username: ')) if (!rootProject.hasProperty('gitPassword')) @@ -275,7 +268,4 @@ task setupRelease { System.setProperty('org.ajoberstar.grgit.auth.username', rootProject.ext.gitUsername) System.setProperty('org.ajoberstar.grgit.auth.password', rootProject.ext.gitPassword) } -} - -tasks.gitPublishPush.dependsOn(tasks.setupRelease) -tasks.release.dependsOn(tasks.setupRelease) +} \ No newline at end of file diff --git a/bundle/build.gradle b/bundle/build.gradle index fcada3e7..0e7adce7 100644 --- a/bundle/build.gradle +++ b/bundle/build.gradle @@ -46,10 +46,6 @@ shadowJar { r 'SevenZip' mergeServiceFiles() - - doLast { - println("All ${includedDependencies.files}") - } } jar { @@ -60,6 +56,8 @@ publishing { publications { mavenJava(MavenPublication) { p -> project.shadow.component(p) + artifact tasks.getByPath(":javadocJar") + artifact tasks.getByPath(":sourcesJar") pom { name = project.name description = project.description @@ -90,36 +88,19 @@ publishing { } repositories { maven { - name = 'Sonatype' url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' credentials { - username = '' - password = '' + username = rootProject.property("sonatypeUser") + password = rootProject.property("sonatypePass") } } } } signing { - required { gradle.taskGraph.hasTask(':object-client-bundle:setupPublish') } sign publishing.publications.mavenJava } -task setupPublish(dependsOn: ":setupPublish") { - doLast { - ext.'signing.keyId' = rootProject.ext.signingKeyId - ext.'signing.secretKeyRingFile' = rootProject.ext.signingSecretKeyRingFile - ext.'signing.password' = rootProject.ext.signingPass - publishing.repositories.findByName("Sonatype") { - credentials { - username = rootProject.ext.sonatypeUser - password = rootProject.ext.sonatypePass - } - } - } -} -tasks.publishAllPublicationsToSonatypeRepository.dependsOn(tasks.setupPublish) - /** * The unit test task is to verify bundled jar. */