This is an automated email from the ASF dual-hosted git repository.

fanng pushed a commit to branch cherry-pick-pr-10485-branch-1.1
in repository https://gitbox.apache.org/repos/asf/gravitino.git

commit 9ddfe889f0bd2ab1b8def3bf50d636ae69f83e0c
Author: FANNG <[email protected]>
AuthorDate: Fri Mar 20 12:34:35 2026 +0900

    [#10262] refactor(build): remove release task and centralize JDK8 
compatibility (#10385)
    
    This PR removes the dedicated `release` Gradle task path and centralizes
    JDK8 compatibility handling in the root build configuration.
    
    1. Removed the root `release` task from `build.gradle.kts`.
    2. Updated `dev/release/release-build.sh` to use `assemble` instead of
    `release` for the publish preflight.
    3. Updated the lightweight CI compile check to use `./gradlew assemble`.
    4. Centralized JDK8-compatible project matching logic in the root
    `build.gradle.kts`.
    5. Simplified the JDK8-compatible module selection into a single
    project-path-prefix rule.
    6. Configured all JDK8-compatible projects to compile `main` sources
    with `--release 8`.
    7. Configured tests for those projects to resolve and compile with JDK
    17 by setting `compileTestJava --release 17` and `TargetJvmVersion=17`
    on test classpaths.
    8. Removed duplicated test JVM compatibility wiring from
    `clients/client-java/build.gradle.kts`.
    9. Set `JavaCompile` encoding to `UTF-8` in the root build so existing
    non-ASCII sources compile consistently across environments.
    
    Previously, producing JDK8-compatible artifacts depended on a separate
    `./gradlew release` path, and the compatibility logic was split across
    the root build and individual modules.
    
    This change makes the build behavior more consistent by:
    
    - removing the dedicated `release` task path,
    - using standard Gradle `build`/`assemble` flows instead of a custom
    release lifecycle,
    - keeping JDK8 compatibility decisions in one place,
    - compiling JDK8-targeted main artifacts consistently,
    - and letting tests continue to compile and run against JDK17
    dependencies where needed.
    
    Fix: #10262
    
    No user-facing API or property-key changes.
    
    This is a build-system/internal compatibility cleanup.
    
    Ran targeted verification for the centralized JDK8/JDK17 build behavior:
    
    1. `./gradlew :clients:client-java:printJvm :clients:cli:printJvm
    :clients:filesystem-hadoop3:printJvm :maintenance:jobs:printJvm
    :spark-connector:spark-common:printJvm :flink-connector:flink:printJvm
    -PskipITs`
    2. `./gradlew :clients:filesystem-hadoop3:compileTestJava
    :maintenance:jobs:compileTestJava :clients:client-java:compileTestJava
    :spark-connector:spark-common:compileTestJava
    :flink-connector:flink:compileTestJava -PskipITs --console=plain`
    3. `./gradlew :api:compileJava :common:compileJava
    :clients:cli:compileJava :clients:client-java:compileTestJava
    :spark-connector:spark-common:compileJava
    :spark-connector:spark-common:compileTestJava -PskipITs --console=plain`
    4. `./gradlew :spark-connector:spark-runtime-3.5:shadowJar
    --console=plain`
    5. `./gradlew spotlessKotlinGradleCheck --console=plain`
    6. `./gradlew :api:compileJava :clients:client-java:compileTestJava
    -PskipITs --console=plain`
    
    Also manually verified:
    
    - `:api:compileJava` rejects a temporary Java 9 API usage at compile
    time under the JDK8 target.
    - The built Spark 3.5 runtime shadow jar has base class-file version 52
    (Java 8) on its main classpath entries.
    - There are no remaining `./gradlew release` or `gradlew release` task
    invocations in the repository.
    
    (cherry picked from commit a408ae2d053c124bddd83b4e422a6df1a8b6e7a5)
---
 .github/workflows/build.yml  |  5 +--
 build.gradle.kts             | 82 +++++++++++++++++++-------------------------
 dev/release/release-build.sh |  4 +--
 3 files changed, 39 insertions(+), 52 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 8936a8e1c8..802ee99377 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -68,7 +68,7 @@ jobs:
 
       - name: Build with Gradle
         run: |
-          ./gradlew release -x test
+          ./gradlew assemble
 
   # To check the spark-connector is compatible with scala2.13
   spark-connector-build:
@@ -144,9 +144,6 @@ jobs:
         if: needs.changes.outputs.mcp_server_changes != 'true'
         run: ./gradlew build -PskipITs -PskipDockerTests=false -x 
:clients:client-python:build -x :mcp-server:build -x :mcp-server:test -x 
:mcp-server:pylint
 
-      - name: Release with Gradle
-        run: ./gradlew clean && ./gradlew release -x test --rerun-tasks
-
       - name: Upload unit tests report
         uses: actions/upload-artifact@v4
         if: failure()
diff --git a/build.gradle.kts b/build.gradle.kts
index 96089d9b8e..3a60735e15 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -24,6 +24,7 @@ import 
com.github.jk1.license.render.InventoryHtmlReportRenderer
 import com.github.jk1.license.render.ReportRenderer
 import com.github.vlsi.gradle.dsl.configureEach
 import net.ltgt.gradle.errorprone.errorprone
+import org.gradle.api.attributes.java.TargetJvmVersion
 import org.gradle.api.tasks.testing.logging.TestExceptionFormat
 import org.gradle.internal.hash.ChecksumService
 import org.gradle.internal.os.OperatingSystem
@@ -313,30 +314,23 @@ subprojects {
     mavenLocal()
   }
 
-  fun compatibleWithJDK8(project: Project): Boolean {
-    val isReleaseRun = gradle.startParameter.taskNames.any { it == "release" 
|| it == "publish" || it == "publishToMavenLocal" }
-    if (!isReleaseRun) {
-      return false
-    }
+  val jdk8CompatibleProjectPathPrefixes = setOf(
+    ":api",
+    ":common",
+    ":catalogs:catalog-common",
+    ":catalogs:hadoop-common",
+    ":maintenance:jobs",
+    ":maintenance:optimizer-api",
+    ":maintenance:updaters",
+    ":clients",
+    ":bundles",
+    ":spark-connector",
+    ":flink-connector"
+  )
 
-    val name = project.name.lowercase()
+  fun compatibleWithJDK8(project: Project): Boolean {
     val path = project.path.lowercase()
-
-    if (path.startsWith(":client") ||
-      path.startsWith(":spark-connector") ||
-      path.startsWith(":flink-connector") ||
-      path.startsWith(":bundles")
-    ) {
-      return true
-    }
-
-    if (name == "api" || name == "common" ||
-      name == "catalog-common" || name == "hadoop-common"
-    ) {
-      return true
-    }
-
-    return false
+    return jdk8CompatibleProjectPathPrefixes.any { path.startsWith(it) }
   }
   extensions.extraProperties.set("excludePackagesForSparkConnector", 
::excludePackagesForSparkConnector)
 
@@ -372,12 +366,6 @@ subprojects {
     }
   }
 
-  tasks.withType<JavaCompile>().configureEach {
-    if (compatibleWithJDK8(project)) {
-      options.release.set(8)
-    }
-  }
-
   java {
     toolchain {
       // Some JDK vendors like Homebrew installed OpenJDK 17 have problems in 
building trino-connector:
@@ -399,6 +387,24 @@ subprojects {
     }
   }
 
+  if (compatibleWithJDK8(project)) {
+    // Keep published/main classes Java 8-compatible for the selected modules.
+    tasks.named<JavaCompile>("compileJava") {
+      options.release.set(8)
+    }
+
+    // Tests still need Java 17 to compile against dependencies that only 
publish Java 17 variants.
+    tasks.named<JavaCompile>("compileTestJava") {
+      options.release.set(17)
+    }
+
+    val targetJvmVersionAttribute = 
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
+    configurations.matching { it.name in setOf("testCompileClasspath", 
"testRuntimeClasspath") }
+      .configureEach {
+        attributes.attribute(targetJvmVersionAttribute, 17)
+      }
+  }
+
   gradle.projectsEvaluated {
     tasks.withType<JavaCompile> {
       options.compilerArgs.addAll(
@@ -423,6 +429,8 @@ subprojects {
   }
 
   tasks.withType<JavaCompile>().configureEach {
+    // Keep Java compilation independent of the host's default charset.
+    options.encoding = "UTF-8"
     options.errorprone.isEnabled.set(true)
     options.errorprone.disableWarningsInGeneratedCode.set(true)
     options.errorprone.disable(
@@ -1214,21 +1222,3 @@ fun checkOrbStackStatus() {
 }
 
 printDockerCheckInfo()
-
-tasks.register("release") {
-  group = "release"
-  description = "Builds and package a release version."
-  doFirst {
-    println("Releasing project...")
-  }
-
-  // Use 'assemble' instead of 'build' to skip tests during release
-  // Tests have JDK version conflicts (some need JDK 8, some need JDK 17)
-  // and should be run separately in CI/CD with appropriate JDK configurations
-  // Only include subprojects that apply the Java plugin (exclude 
client-python)
-  dependsOn(
-    subprojects
-      .filter { it.name != "client-python" }
-      .map { it.tasks.named("assemble") }
-  )
-}
diff --git a/dev/release/release-build.sh b/dev/release/release-build.sh
index 5bd14b90eb..49d9e5b846 100755
--- a/dev/release/release-build.sh
+++ b/dev/release/release-build.sh
@@ -341,8 +341,8 @@ if [[ "$1" == "publish-release" ]]; then
   cd ..
 
   $GRADLE clean
-  $GRADLE release -x test -PdefaultScalaVersion=2.12
-  $GRADLE release -x test -PdefaultScalaVersion=2.13
+  $GRADLE assemble -PdefaultScalaVersion=2.12
+  $GRADLE assemble -PdefaultScalaVersion=2.13
 
   $GRADLE -Dmaven.repo.local=$tmp_repo publishToMavenLocal 
-PdefaultScalaVersion=2.12
   $GRADLE -Dmaven.repo.local=$tmp_repo publishToMavenLocal 
-PdefaultScalaVersion=2.13

Reply via email to