Skip to content

Commit

Permalink
[#906] fix(test): Fix spotless issue when running against JDK21 (#934)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Current spotless plugin has issues running against JDK21
(diffplug/spotless#1819), but we cannot
upgrade the spotless version to a newer version to fix this issue,
because newer version of Spotless requires at least JDK11. So for now,
we enforce the JDK version to <= 17 when we running Gradle.

### Why are the changes needed?

Fix the problem when Gradle running with JDK21.

Fix: #906 

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Verified locally on JDK 8, 11, 17 between macOS and Ubuntu.
  • Loading branch information
jerryshao authored Dec 5, 2023
1 parent 68af8d6 commit f1e4e3d
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 29 deletions.
1 change: 0 additions & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
20 changes: 15 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Copyright 2023 Datastrato.
* This software is licensed under the Apache License version 2.
*/
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessPlugin
import com.github.vlsi.gradle.dsl.configureEach
import java.util.Locale
import java.io.File
Expand All @@ -21,7 +19,18 @@ plugins {
id("idea")
id("jacoco")
alias(libs.plugins.gradle.extensions)
alias(libs.plugins.spotless)

// Spotless version < 6.19.0 (https://github.com/diffplug/spotless/issues/1819) has an issue
// running against JDK21, but we cannot upgrade the spotless to 6.19.0 or later since it only
// support JDK11+. So we don't support JDK21 and thrown an exception for now.
if (JavaVersion.current() >= JavaVersion.VERSION_1_8
&& JavaVersion.current() <= JavaVersion.VERSION_17) {
alias(libs.plugins.spotless)
} else {
throw GradleException("Gravitino Gradle current doesn't support " +
"Java version: ${JavaVersion.current()}. Please use JDK8 to 17.")
}

alias(libs.plugins.publish)
// Apply one top level rat plugin to perform any required license enforcement analysis
alias(libs.plugins.rat)
Expand Down Expand Up @@ -71,6 +80,7 @@ subprojects {
apply(plugin = "jacoco")
apply(plugin = "maven-publish")
apply(plugin = "java")
apply(plugin = "com.diffplug.spotless")

repositories {
mavenCentral()
Expand Down Expand Up @@ -185,8 +195,8 @@ subprojects {
}
}

plugins.withType<SpotlessPlugin>().configureEach {
configure<SpotlessExtension> {
plugins.withType<com.diffplug.gradle.spotless.SpotlessPlugin>().configureEach {
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
java {
// Fix the Google Java Format version to 1.7. Since JDK8 only support Google Java Format
// 1.7, which is not compatible with JDK17. We will use a newer version when we upgrade to
Expand Down
1 change: 0 additions & 1 deletion catalogs/catalog-hive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion catalogs/catalog-jdbc-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion catalogs/catalog-jdbc-mysql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion catalogs/catalog-lakehouse-iceberg/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ public void close() {}
@Override
public NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {
try {
List<org.apache.iceberg.catalog.Namespace> namespaces =
icebergTableOps.listNamespace(IcebergTableOpsHelper.getIcebergNamespace()).namespaces();

return icebergTableOps.listNamespace(IcebergTableOpsHelper.getIcebergNamespace()).namespaces()
.stream()
return namespaces.stream()
.map(icebergNamespace -> NameIdentifier.of(icebergNamespace.levels()))
.toArray(NameIdentifier[]::new);
} catch (NoSuchNamespaceException e) {
Expand Down
1 change: 0 additions & 1 deletion clients/client-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private byte[] formatNameIdentifierTemplateToByte(String[] nameIdentifierTemplat

return bytes;
}

/**
* Encodes an entity object into a byte array for use as a key in a key-value store.
*
Expand Down
23 changes: 18 additions & 5 deletions docs/how-to-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ This software is licensed under the Apache License version 2."

+ Linux or macOS operating system
+ Git
+ A Java Development Kit version 8 or later version installed in your environment to launch Gradle
+ A Java Development Kit version 8 to 17 installed in your environment to launch Gradle
+ Optionally Docker to run integration tests

Note:

+ Gravitino requires at least JDK8 and at most JDK17 to run Gradle, so you need to
install JDK8 to 17 version to launch the build environment.

+ Gravitino itself uses JDK8 to build, Gravitino Trino connector uses JDK17 to build. You don't
have to preinstall JDK8 or JDK17, Gradle detects the JDK version needed and downloads it automatically.

Expand All @@ -24,8 +27,11 @@ Note:

+ Make sure you have installed Docker in your environment as Gravitino uses it to run integration tests; without it, some Docker-related tests may not run.

+ OSX uses "docker-connector" to make the Gravitino Trino connector work with Docker
for Mac. For the details of "docker-connector", please see [docker-connector](https://github.com/wenjunxiao/mac-docker-connector) and [README](../dev/docker/tools/README.md).
+ macOS uses "docker-connector" to make the Gravitino Trino connector work with Docker
for macOS. For the details of "docker-connector", please see [docker-connector](https://github.com/wenjunxiao/mac-docker-connector) and [README](../dev/docker/tools/README.md).
Alternatively, you can use OrbStack to replace Docker for macOS, please see
[OrbStack](https://orbstack.dev/), with OrbStack you can run Gravitino integration tests
without needing to install "docker-connector".

## Quick start

Expand Down Expand Up @@ -80,8 +86,15 @@ Note:

You can access the Gravitino WEB UI by typing http://localhost:8090 in your browser

> Note: If you need to debug the Gravitino Server, enable the `GRAVITINO_DEBUG_OPTS` environment variable in the `conf/gravitino-env.sh` file.
Then you can create a `Remote JVM Debug` configuration in `IntelliJ IDEA` and debug `gravitino.server.main`.
> Note:
>
> If you need to debug the Gravitino server, enable the `GRAVITINO_DEBUG_OPTS` environment
> variable in the `conf/gravitino-env.sh` file. Then you can create a `Remote JVM Debug`
> configuration in `IntelliJ IDEA` and debug `gravitino.server.main`.
>
> Currently, Gravitino server can only run with JDK8 due to some dependencies. Please
> make sure you have JDK8 installed and `JAVA_HOME` configured correctly. To check the Jave
> version, you can simply run `${JAVA_HOME}/bin/java -version` command.

5. Stop Gravitino Server.

Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ trino-jdbc = "426"
jwt = "0.11.1"
jline = "3.21.0"
okhttp3 = "4.11.0"
metrics = "4.2.19"
prometheus = "0.16.0"
jsqlparser = "4.2"
mysql = "8.0.23"

protobuf-plugin = "0.9.2"
spotless-plugin = '6.11.0'
gradle-extensions-plugin = '1.74'
publish-plugin = '1.2.0'
rat-plugin = '0.8.0'
shadow-plugin = "8.1.1"
metrics = "4.2.19"
prometheus = "0.16.0"
jsqlparser = "4.2"
mysql = "8.0.23"

[libraries]
protobuf-java = { group = "com.google.protobuf", name = "protobuf-java", version.ref = "protoc" }
Expand Down
1 change: 0 additions & 1 deletion integration-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion meta/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
id("java")
id("idea")
alias(libs.plugins.protobuf)
alias(libs.plugins.spotless)
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion trino-connector/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`maven-publish`
id("java")
id("idea")
id("com.diffplug.spotless")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ default List<PropertyMetadata<?>> getTableProperties() {
/** @return SchemaProperties list that used to validate schema properties. */
default List<PropertyMetadata<?>> getSchemaProperties() {
return emptyList();
};
}

/** @return Return MetadataAdapter for special catalog connector. */
CatalogConnectorMetadataAdapter getMetadataAdapter();
Expand Down

0 comments on commit f1e4e3d

Please sign in to comment.