From b35c5924b395133c64a93dc2f979a64bf2df0ef6 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 8 Jan 2025 17:19:28 -0800 Subject: [PATCH 01/11] Shadow protobuf Signed-off-by: Yury-Fridlyand --- CHANGELOG.md | 1 + java/client/build.gradle | 9 +++++++++ java/integTest/build.gradle | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c724e6c52..b860a97d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * Java: Add binary version of `ZRANK WITHSCORE` ([#2896](https://github.com/valkey-io/valkey-glide/pull/2896)) * Go: Add `ZCARD` ([#2838](https://github.com/valkey-io/valkey-glide/pull/2838)) * Go: Add `BZPopMin` ([#2849](https://github.com/valkey-io/valkey-glide/pull/2849)) +* Java: Shadow `protobuf` dependency ([#2931](https://github.com/valkey-io/valkey-glide/pull/2931)) #### Breaking Changes diff --git a/java/client/build.gradle b/java/client/build.gradle index 7ae0d7c429..0c9bd84b3f 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -7,6 +7,15 @@ plugins { id 'io.freefair.lombok' version '8.6' id 'com.github.spotbugs' version '6.0.18' id 'com.google.osdetector' version '1.7.3' + id 'com.gradleup.shadow' version '8.3.5' +} + +shadowJar { + dependsOn('copyNativeLib') + dependencies { + include dependency('com.google.protobuf:protobuf-java:4.29.1') + } + archiveClassifier = osdetector.classifier } repositories { diff --git a/java/integTest/build.gradle b/java/integTest/build.gradle index 8ebd7f272e..7aca787452 100644 --- a/java/integTest/build.gradle +++ b/java/integTest/build.gradle @@ -1,14 +1,16 @@ plugins { id 'java-library' + id "com.google.osdetector" version "1.7.3" } repositories { mavenCentral() + mavenLocal() } dependencies { // client - implementation project(':client') + implementation group: 'io.valkey', name: 'valkey-glide', version: '255.255.255', classifier: osdetector.classifier implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' implementation 'com.google.code.gson:gson:2.10.1' @@ -129,7 +131,7 @@ clearDirs.finalizedBy 'startStandalone' clearDirs.finalizedBy 'startCluster' clearDirs.finalizedBy 'startClusterForAz' test.finalizedBy 'stopAllAfterTests' -test.dependsOn ':client:buildRust' +test.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' tasks.withType(Test) { doFirst { From 8aad5da469d67758a84296607dc0aa3abf4feba7 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 8 Jan 2025 18:01:52 -0800 Subject: [PATCH 02/11] modules Signed-off-by: Yury-Fridlyand --- java/integTest/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/java/integTest/build.gradle b/java/integTest/build.gradle index 7aca787452..8ec4aacd38 100644 --- a/java/integTest/build.gradle +++ b/java/integTest/build.gradle @@ -162,6 +162,7 @@ test { } tasks.register('modulesTest', Test) { + dependsOn ':client:publishMavenJavaPublicationToMavenLocal' doFirst { clusterHosts = System.getProperty("cluster-endpoints") } From 576a6b55382e103d6f03d4e4f787896c3e679121 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 8 Jan 2025 18:31:46 -0800 Subject: [PATCH 03/11] fix Signed-off-by: Yury-Fridlyand --- java/.ort.yml | 3 +++ java/integTest/build.gradle | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/java/.ort.yml b/java/.ort.yml index ace1740f01..260893f21a 100644 --- a/java/.ort.yml +++ b/java/.ort.yml @@ -21,3 +21,6 @@ excludes: - pattern: "compileClasspath.*" reason: "TEST_DEPENDENCY_OF" comment: Packages for Gradle only. Not part of released artifacts. + - pattern: "io.valkey.valkey-glide.*" + reason: "TEST_DEPENDENCY_OF" + comment: A module of Valkey-Glide java client built during tests. diff --git a/java/integTest/build.gradle b/java/integTest/build.gradle index 8ec4aacd38..5e64593b0c 100644 --- a/java/integTest/build.gradle +++ b/java/integTest/build.gradle @@ -131,7 +131,7 @@ clearDirs.finalizedBy 'startStandalone' clearDirs.finalizedBy 'startCluster' clearDirs.finalizedBy 'startClusterForAz' test.finalizedBy 'stopAllAfterTests' -test.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' +compileTestJava.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' tasks.withType(Test) { doFirst { @@ -162,7 +162,6 @@ test { } tasks.register('modulesTest', Test) { - dependsOn ':client:publishMavenJavaPublicationToMavenLocal' doFirst { clusterHosts = System.getProperty("cluster-endpoints") } From 91f9de839d0d89ad362898942aa6526b33ea61a4 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 9 Jan 2025 11:23:55 -0800 Subject: [PATCH 04/11] ort Signed-off-by: Yury-Fridlyand --- .github/workflows/ort.yml | 5 +++++ java/.ort.yml | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ort.yml b/.github/workflows/ort.yml index 0f1b394880..f7c7a26374 100644 --- a/.github/workflows/ort.yml +++ b/.github/workflows/ort.yml @@ -158,6 +158,11 @@ jobs: distribution: "temurin" java-version: 11 + - name: Build java artifact + working-directory: ./java + run: | + ./gradlew publishMavenJavaPublicationToMavenLocal -x buildRust -x javadoc + - name: Run ORT tools for Java uses: ./.github/workflows/run-ort-tools with: diff --git a/java/.ort.yml b/java/.ort.yml index 260893f21a..ace1740f01 100644 --- a/java/.ort.yml +++ b/java/.ort.yml @@ -21,6 +21,3 @@ excludes: - pattern: "compileClasspath.*" reason: "TEST_DEPENDENCY_OF" comment: Packages for Gradle only. Not part of released artifacts. - - pattern: "io.valkey.valkey-glide.*" - reason: "TEST_DEPENDENCY_OF" - comment: A module of Valkey-Glide java client built during tests. From 345329459bda3d805d9adde8c70d18a9b50cc2c0 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 9 Jan 2025 11:42:47 -0800 Subject: [PATCH 05/11] refactor Signed-off-by: Yury-Fridlyand --- .github/workflows/ort.yml | 6 ++++++ java/build.gradle | 5 ++++- java/client/build.gradle | 4 +--- java/integTest/build.gradle | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ort.yml b/.github/workflows/ort.yml index f7c7a26374..71ed7f98a9 100644 --- a/.github/workflows/ort.yml +++ b/.github/workflows/ort.yml @@ -158,6 +158,12 @@ jobs: distribution: "temurin" java-version: 11 + - name: Install protoc (protobuf) + uses: arduino/setup-protoc@v3 + with: + version: "29.1" + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Build java artifact working-directory: ./java run: | diff --git a/java/build.gradle b/java/build.gradle index 1db21c0404..31acdb0902 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -41,7 +41,10 @@ subprojects { // finalizedBy jacocoTestReport, jacocoTestCoverageVerification } - ext.failedTests = [] + ext { + defaultReleaseVersion = "255.255.255" + failedTests = [] + } tasks.withType(Test) { afterTest { TestDescriptor descriptor, TestResult result -> diff --git a/java/client/build.gradle b/java/client/build.gradle index 0c9bd84b3f..48b65a40fc 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -139,8 +139,6 @@ tasks.register('copyNativeLib', Copy) { into sourceSets.main.output.resourcesDir } -def defaultReleaseVersion = "255.255.255"; - delombok.dependsOn('compileJava') jar.dependsOn('copyNativeLib') javadoc.dependsOn('copyNativeLib') @@ -170,7 +168,7 @@ publishing { from components.java groupId = 'io.valkey' artifactId = 'valkey-glide' - version = System.getenv("GLIDE_RELEASE_VERSION") ?: defaultReleaseVersion; + version = System.getenv("GLIDE_RELEASE_VERSION") ?: project.ext.defaultReleaseVersion pom { name = 'valkey-glide' description = 'General Language Independent Driver for the Enterprise (GLIDE) for Valkey' diff --git a/java/integTest/build.gradle b/java/integTest/build.gradle index 5e64593b0c..1112adc7d3 100644 --- a/java/integTest/build.gradle +++ b/java/integTest/build.gradle @@ -10,7 +10,7 @@ repositories { dependencies { // client - implementation group: 'io.valkey', name: 'valkey-glide', version: '255.255.255', classifier: osdetector.classifier + implementation group: 'io.valkey', name: 'valkey-glide', version: project.ext.defaultReleaseVersion, classifier: osdetector.classifier implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' implementation 'com.google.code.gson:gson:2.10.1' From 1c76e3acbe3acd5ab038af270fb0ff25c87a61a4 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 9 Jan 2025 15:33:18 -0800 Subject: [PATCH 06/11] fixes Signed-off-by: Yury-Fridlyand --- java/benchmarks/build.gradle | 11 ++++------- java/client/build.gradle | 15 ++++++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/java/benchmarks/build.gradle b/java/benchmarks/build.gradle index b4777ee410..5d710b659f 100644 --- a/java/benchmarks/build.gradle +++ b/java/benchmarks/build.gradle @@ -7,16 +7,13 @@ plugins { repositories { // Use Maven Central for resolving dependencies. mavenCentral() + mavenLocal() } dependencies { - def releaseVersion = System.getenv("GLIDE_RELEASE_VERSION"); + version = System.getenv("GLIDE_RELEASE_VERSION") ?: project.ext.defaultReleaseVersion - if (releaseVersion) { - implementation "io.valkey:valkey-glide:" + releaseVersion + ":${osdetector.classifier}" - } else { - implementation project(':client') - } + implementation "io.valkey:valkey-glide:${version}:${osdetector.classifier}" // This dependency is used internally, and not exposed to consumers on their own compile classpath. implementation 'com.google.guava:guava:32.1.1-jre' @@ -28,7 +25,7 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' } -run.dependsOn ':client:buildRust' +run.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' application { // Define the main class for the application. diff --git a/java/client/build.gradle b/java/client/build.gradle index 48b65a40fc..78db2f0fbe 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -12,9 +12,6 @@ plugins { shadowJar { dependsOn('copyNativeLib') - dependencies { - include dependency('com.google.protobuf:protobuf-java:4.29.1') - } archiveClassifier = osdetector.classifier } @@ -24,14 +21,14 @@ repositories { dependencies { implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '4.29.1' - implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' + shadow group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' - implementation group: 'io.netty', name: 'netty-handler', version: '4.1.115.Final' + shadow group: 'io.netty', name: 'netty-handler', version: '4.1.115.Final' // https://github.com/netty/netty/wiki/Native-transports // At the moment, Windows is not supported - implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.115.Final', classifier: 'linux-x86_64' - implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.115.Final', classifier: 'linux-aarch_64' - implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: '4.1.115.Final', classifier: 'osx-aarch_64' + shadow group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.115.Final', classifier: 'linux-x86_64' + shadow group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.115.Final', classifier: 'linux-aarch_64' + shadow group: 'io.netty', name: 'netty-transport-native-kqueue', version: '4.1.115.Final', classifier: 'osx-aarch_64' // junit testImplementation group: 'org.mockito', name: 'mockito-inline', version: '3.12.4' @@ -165,7 +162,7 @@ sourceSets { publishing { publications { mavenJava(MavenPublication) { - from components.java + from components.shadow groupId = 'io.valkey' artifactId = 'valkey-glide' version = System.getenv("GLIDE_RELEASE_VERSION") ?: project.ext.defaultReleaseVersion From 3b6e01f10b2cb43b83421e128b1955b8340a80bf Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 9 Jan 2025 15:55:21 -0800 Subject: [PATCH 07/11] ut Signed-off-by: Yury-Fridlyand --- java/client/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/client/build.gradle b/java/client/build.gradle index 78db2f0fbe..bfb267b027 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -19,6 +19,10 @@ repositories { mavenCentral() } +configurations { + testImplementation { extendsFrom shadow } +} + dependencies { implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '4.29.1' shadow group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' From 94ee1aa391234aa4252c8ed4f73bfeba21dd3a1f Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 9 Jan 2025 16:15:48 -0800 Subject: [PATCH 08/11] fix Signed-off-by: Yury-Fridlyand --- java/client/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/client/build.gradle b/java/client/build.gradle index bfb267b027..e0d7213eb0 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -201,6 +201,10 @@ publishing { } } +tasks.withType(GenerateModuleMetadata) { + dependsOn jar, shadowJar +} + java { modularity.inferModulePath = true withSourcesJar() From a76b5194bc0078875f5df60e3f0c75923c2d22e0 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 9 Jan 2025 16:40:37 -0800 Subject: [PATCH 09/11] fix Signed-off-by: Yury-Fridlyand --- java/benchmarks/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/benchmarks/build.gradle b/java/benchmarks/build.gradle index 5d710b659f..c322599b8d 100644 --- a/java/benchmarks/build.gradle +++ b/java/benchmarks/build.gradle @@ -25,7 +25,7 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' } -run.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' +compileJava.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' application { // Define the main class for the application. From 90489cb2e7e3674d7f03f03f4231270840550488 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Fri, 10 Jan 2025 13:02:19 -0800 Subject: [PATCH 10/11] fixes Signed-off-by: Yury-Fridlyand --- java/benchmarks/build.gradle | 2 +- java/client/build.gradle | 23 ++++++++++++++++++----- java/integTest/build.gradle | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/java/benchmarks/build.gradle b/java/benchmarks/build.gradle index c322599b8d..f8e62ab6d7 100644 --- a/java/benchmarks/build.gradle +++ b/java/benchmarks/build.gradle @@ -25,7 +25,7 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' } -compileJava.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' +compileJava.dependsOn ':client:publishToMavenLocal' application { // Define the main class for the application. diff --git a/java/client/build.gradle b/java/client/build.gradle index e0d7213eb0..008c1c68a6 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -10,11 +10,6 @@ plugins { id 'com.gradleup.shadow' version '8.3.5' } -shadowJar { - dependsOn('copyNativeLib') - archiveClassifier = osdetector.classifier -} - repositories { mavenCentral() } @@ -167,6 +162,8 @@ publishing { publications { mavenJava(MavenPublication) { from components.shadow + artifact javadocJar + artifact sourcesJar groupId = 'io.valkey' artifactId = 'valkey-glide' version = System.getenv("GLIDE_RELEASE_VERSION") ?: project.ext.defaultReleaseVersion @@ -235,6 +232,11 @@ jar { archiveClassifier = osdetector.classifier } +shadowJar { + dependsOn('copyNativeLib') + archiveClassifier = osdetector.classifier +} + sourcesJar { // suppress following error // Entry glide/api/BaseClient.java is a duplicate but no duplicate handling strategy has been set @@ -252,6 +254,17 @@ javadoc { failOnError = false // TODO fix all javadoc errors and warnings and remove that } +task javadocJar(type: Jar, dependsOn: javadoc) { + archiveClassifier = 'javadoc' + from javadoc.destinationDir +} + +task sourcesJar(type: Jar, dependsOn: classes) { + archiveClassifier = 'sources' + from sourceSets.main.allSource + exclude 'glide/models' // exclude protobuf files +} + spotbugsMain { reports { html { diff --git a/java/integTest/build.gradle b/java/integTest/build.gradle index 1112adc7d3..ebe42ce072 100644 --- a/java/integTest/build.gradle +++ b/java/integTest/build.gradle @@ -131,7 +131,7 @@ clearDirs.finalizedBy 'startStandalone' clearDirs.finalizedBy 'startCluster' clearDirs.finalizedBy 'startClusterForAz' test.finalizedBy 'stopAllAfterTests' -compileTestJava.dependsOn ':client:publishMavenJavaPublicationToMavenLocal' +compileTestJava.dependsOn ':client:publishToMavenLocal' tasks.withType(Test) { doFirst { From a94cca1520c9bca08d9ffe55568c915ff67ea8d0 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Fri, 10 Jan 2025 13:15:36 -0800 Subject: [PATCH 11/11] fixes Signed-off-by: Yury-Fridlyand --- .github/workflows/ort.yml | 2 +- java/client/build.gradle | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ort.yml b/.github/workflows/ort.yml index 71ed7f98a9..051400236c 100644 --- a/.github/workflows/ort.yml +++ b/.github/workflows/ort.yml @@ -167,7 +167,7 @@ jobs: - name: Build java artifact working-directory: ./java run: | - ./gradlew publishMavenJavaPublicationToMavenLocal -x buildRust -x javadoc + ./gradlew publishToMavenLocal -x buildRust -x javadoc - name: Run ORT tools for Java uses: ./.github/workflows/run-ort-tools diff --git a/java/client/build.gradle b/java/client/build.gradle index 008c1c68a6..efdbd6b7f8 100644 --- a/java/client/build.gradle +++ b/java/client/build.gradle @@ -158,6 +158,17 @@ sourceSets { } } +task javadocJar(type: Jar, dependsOn: javadoc) { + archiveClassifier = 'javadoc' + from javadoc.destinationDir +} + +task sourcesJar(type: Jar, dependsOn: classes) { + archiveClassifier = 'sources' + from sourceSets.main.allSource + exclude 'glide/models' // exclude protobuf files +} + publishing { publications { mavenJava(MavenPublication) { @@ -254,17 +265,6 @@ javadoc { failOnError = false // TODO fix all javadoc errors and warnings and remove that } -task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier = 'javadoc' - from javadoc.destinationDir -} - -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource - exclude 'glide/models' // exclude protobuf files -} - spotbugsMain { reports { html {