-
Notifications
You must be signed in to change notification settings - Fork 333
Remove remaining use of JAVA_X_HOME
#10340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
34aa680
10a114f
331caaf
f27e5c1
0ee2ca4
a49b7a3
bea5f86
f13392e
5ba7a07
b54568a
2c12ef8
e55a0a4
e6645d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,14 +29,9 @@ or on Windows: | |
| Your output should look something like the following: | ||
|
|
||
| ``` | ||
| ℹ️ Checking required JVMs: | ||
| ✅ JAVA_HOME is set to /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home. | ||
| ✅ JAVA_8_HOME is set to /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home. | ||
| ✅ JAVA_11_HOME is set to /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home. | ||
| ✅ JAVA_17_HOME is set to /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home. | ||
| ✅ JAVA_21_HOME is set to /Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home. | ||
| ✅ JAVA_25_HOME is set to /Library/Java/JavaVirtualMachines/zulu-25.jdk/Contents/Home. | ||
| ✅ JAVA_GRAALVM17_HOME is set to /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.1/Contents/Home. | ||
| ℹ️ Checking required JVM: | ||
| ✅ JAVA_HOME is set to /Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home. | ||
| ℹ️ Other JDK versions will be automatically downloaded by Gradle toolchain resolver. | ||
| ℹ️ Checking git configuration: | ||
| ✅ The git command line is installed. | ||
| ✅ pre-commit hook is installed in repository. | ||
|
|
@@ -53,19 +48,20 @@ If there is any issue with your output, check the requirements above and use the | |
|
|
||
| Requirements to build the full project: | ||
|
|
||
| * The JDK versions 8, 11, 17, 21, and 25 must be installed. | ||
| * The `JAVA_8_HOME`, `JAVA_11_HOME`, `JAVA_17_HOME`, `JAVA_21_HOME`, `JAVA_25_HOME`, and `JAVA_GRAALVM17_HOME` must point to their respective JDK location. | ||
| * The JDK 8 `bin` directory must be the only JDK on the PATH (e.g. `$JAVA_8_HOME/bin`). | ||
| * The `JAVA_HOME` environment variable may be unset. If set, it must point to the JDK 8 location (same as `JAVA_8_HOME`). | ||
| * JDK 21 must be installed and `JAVA_HOME` must point to it. | ||
| * Other JDK versions (8, 11, 17, 25) will be automatically downloaded by Gradle's toolchain resolver. | ||
|
bric3 marked this conversation as resolved.
Outdated
|
||
| * The `git` command line must be installed. | ||
| * A container runtime environment must be available to run all tests (e.g. Docker Desktop). | ||
|
|
||
| ### Install the required JDKs | ||
| ### Install the required JDK | ||
|
|
||
| Download and install JDK versions 8, 11, 17, 21 and 25, and GraalVM 17 for your OS. | ||
| Download and install JDK 21 for your OS. Other JDK versions will be automatically downloaded by Gradle when needed. | ||
|
|
||
| #### macOS | ||
|
|
||
|
|
||
| Use your JDK manager ([mise](https://mise.jdx.dev/), [sdkman](https://sdkman.io/), etc.) or set-up the required JDKs with `brew` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 thought: This is confusing as the next section gives explanations for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reworded |
||
|
|
||
| * Install the required JDKs using `brew`: | ||
| ```shell | ||
| brew install --cask zulu@8 zulu@11 zulu@17 zulu@21 zulu graalvm/tap/graalvm-ce-java17 | ||
|
bric3 marked this conversation as resolved.
Outdated
|
||
|
|
@@ -77,20 +73,13 @@ Download and install JDK versions 8, 11, 17, 21 and 25, and GraalVM 17 for your | |
| Example: `graalvm-ce-java17-22.3.1` | ||
| * Use this version in the following command to fix the GraalVM installation by [removing the quarantine flag](https://www.graalvm.org/latest/docs/getting-started/macos/): | ||
| ``` | ||
|
bric3 marked this conversation as resolved.
Outdated
|
||
| sudo xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-<current version of graalvm> | ||
| ``` | ||
| Example: `/Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.1` | ||
| * Add the required environment variables to your shell using the `export` command. You can permanently install the environment variables by appending the `export` commands into your shell configuration file `~/.zshrc` or `.bashrc` or other. | ||
| * Add the `JAVA_HOME` environment variable to your shell using the `export` command. You can permanently set it by appending the `export` command to your shell configuration file `~/.zshrc` or `~/.bashrc` or other. | ||
| ```shell | ||
| export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home | ||
| export JAVA_11_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home | ||
| export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home | ||
| export JAVA_21_HOME=/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home | ||
| export JAVA_25_HOME=/Library/Java/JavaVirtualMachines/zulu-25.jdk/Contents/Home | ||
| export JAVA_GRAALVM17_HOME=/Library/Java/JavaVirtualMachines/graalvm-<current version of graalvm>/Contents/Home | ||
| export JAVA_HOME=$JAVA_8_HOME | ||
| export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home | ||
| ``` | ||
| * Restart your shell after applying the changes if you appended the commands to your shell configuration file. | ||
|
|
||
| Gradle should automatically detect the JDK in usual places. As a fallback it can automatically provision them. | ||
| * Restart your shell after applying the changes if you appended the command to your shell configuration file. | ||
|
|
||
| > [!NOTE] | ||
| > ARM users: there is no Oracle JDK v8 for ARM. | ||
|
|
@@ -102,23 +91,21 @@ Download and install JDK versions 8, 11, 17, 21 and 25, and GraalVM 17 for your | |
|
|
||
| #### Linux | ||
|
|
||
| Use your JDK manager ([mise](https://mise.jdx.dev/), [sdkman](https://sdkman.io/), etc.) or manually install the required JDKs. | ||
|
|
||
| * Download and extract JDK 8, 11, 17, 21, and 25 from [Eclipse Temurin releases](https://adoptium.net/temurin/releases/) and GraalVM 17 from [Oracle downloads](https://www.graalvm.org/downloads/). | ||
| * Install the GraalVM native image requirements for native builds by following [the GraalVM official documentation](https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites). | ||
| * Add the required environment variables to your shell using the `export` command. You can permanently install the environment variables by appending the `export` commands into your shell configuration file `~/.zshrc` or `~/.bashrc` or other. | ||
| * Add the `JAVA_HOME` environment variable to your shell using the `export` command. You can permanently set it by appending the `export` command to your shell configuration file `~/.zshrc` or `~/.bashrc` or other. | ||
| ```shell | ||
| export JAVA_8_HOME=/<path to extracted archive>/jdk8u<current version of JDK 8> | ||
| export JAVA_11_HOME=/<path to extracted archive>/jdk-11.<current version of JDK 11> | ||
| export JAVA_17_HOME=/<path to extracted archive>/jdk-17.<current version of JDK 17> | ||
| export JAVA_21_HOME=/<path to extracted archive>/jdk-21.<current version of JDK 21> | ||
| export JAVA_25_HOME=/<path to extracted archive>/jdk-25.<current version of JDK 25> | ||
| export JAVA_GRAALVM17_HOME=/<path to extracted archive>/graalvm-jdk-17.<current version of graalvm>/Contents/Home | ||
| export JAVA_HOME=$JAVA_8_HOME | ||
| export JAVA_HOME=/<path to extracted archive>/jdk-21.<current version of JDK 21> | ||
| ``` | ||
|
|
||
| Gradle should automatically detect the JDK in usual places. As a fallback it can automatically provision them. | ||
| * Restart your shell after applying the changes if you appended the commands to your shell configuration file. | ||
|
|
||
| #### Windows | ||
|
|
||
| * Download and install JDK 8, 11, 17, 21, and 25 [Eclipse Temurin releases](https://adoptium.net/temurin/releases/). | ||
| * Download and install JDK 8, 11, 17, 21, and 25 from [Eclipse Temurin releases](https://adoptium.net/temurin/releases/). | ||
|
|
||
| <details> | ||
| <summary>Alternatively, install JDKs using winget or scoop. (click here to expand)</summary> | ||
|
|
@@ -142,18 +129,13 @@ Download and install JDK versions 8, 11, 17, 21 and 25, and GraalVM 17 for your | |
|
|
||
| </details> | ||
|
|
||
| * To add the required environment variables, run the following PowerShell commands for each SDK version, replacing the paths with the correct version installed: | ||
| * Set the `JAVA_HOME` environment variable, replacing the path with your JDK 21 installation: | ||
| ```pwsh | ||
| [Environment]::SetEnvironmentVariable("JAVA_8_HOME", "C:\Program Files\Eclipse Adoptium\jdk-8.0.432.6-hotspot", [EnvironmentVariableTarget]::User) | ||
| [Environment]::SetEnvironmentVariable("JAVA_11_HOME", "C:\Program Files\Eclipse Adoptium\jdk-11.0.25.9-hotspot", [EnvironmentVariableTarget]::User) | ||
| [Environment]::SetEnvironmentVariable("JAVA_17_HOME", "C:\Program Files\Eclipse Adoptium\jdk-17.0.12.7-hotspot", [EnvironmentVariableTarget]::User) | ||
| [Environment]::SetEnvironmentVariable("JAVA_21_HOME", "C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot", [EnvironmentVariableTarget]::User) | ||
| [Environment]::SetEnvironmentVariable("JAVA_25_HOME", "C:\Program Files\Eclipse Adoptium\jdk-25.0.1.9-hotspot", [EnvironmentVariableTarget]::User) | ||
|
|
||
| # JAVA_HOME = JAVA_8_HOME | ||
| [Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-8.0.432.6-hotspot", [EnvironmentVariableTarget]::User) | ||
| [Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot", [EnvironmentVariableTarget]::User) | ||
| ``` | ||
|
|
||
| Gradle should automatically detect the JDK in usual places. As a fallback it can automatically provision them. | ||
|
|
||
| ### Install git | ||
|
|
||
| #### macOS | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,10 +50,10 @@ To run the formatting verify task only: | |
|
|
||
| For IntelliJ IDEA, we suggest the following settings and plugin. | ||
|
|
||
| The default JVM to build and run tests from the command line should be Java 8. | ||
| The default JVM to build and run tests from the command line should be Java 21. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ question: Is this still needed? Won't it be picked automatically?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your comment made me realize the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm removing this line as it shouldn't be a concern anymore. |
||
|
|
||
| * Use Java 8 to build and run tests: | ||
| * `Project Structure` -> `Project` -> `SDK` -> `Download JDK...` -> `Version: 1.8` -> `Download` | ||
| * Use Java 21 to build and run tests: | ||
| * `Project Structure` -> `Project` -> `SDK` -> `Download JDK...` -> `Version: 21` -> `Download` | ||
| * Configure Java and Groovy import formatting: | ||
| * `Settings...` ->`Editor` > `Code Style` > `Java` > `Imports` | ||
| * `Use single class import`: checked | ||
|
|
@@ -82,11 +82,6 @@ The default JVM to build and run tests from the command line should be Java 8. | |
| * IntelliJ 2021.3 | ||
| complains `Failed to find KotlinGradleProjectData for GradleSourceSetData` https://youtrack.jetbrains.com/issue/KTIJ-20173. | ||
| * Switch to `IntelliJ IDEA CE 2021.2.3`. | ||
|
|
||
| * IntelliJ Gradle fails to import the project with `JAVA_11_HOME must be set to build Java 11 code`. | ||
| * A workaround is to run IntelliJ from your terminal with `JAVA_11_HOME`. | ||
| * In order to verify what's visible from IntelliJ, use the `Add Configuration` bar and go | ||
| to `Add New` -> `Gradle` -> `Environmental Variables`. | ||
| </details> | ||
|
|
||
| ## Pull request guidelines | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| package datadog.gradle.plugin.testJvmConstraints | ||
|
|
||
| import com.gradle.scan.agent.serialization.scan.serializer.kryo.it | ||
| import org.gradle.api.GradleException | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.internal.project.ProjectInternal | ||
| import org.gradle.api.internal.provider.PropertyFactory | ||
| import org.gradle.api.provider.Provider | ||
| import org.gradle.internal.jvm.inspection.JavaInstallationRegistry | ||
| import org.gradle.jvm.toolchain.JavaLanguageVersion | ||
| import org.gradle.jvm.toolchain.JavaLauncher | ||
| import org.gradle.jvm.toolchain.JavaToolchainService | ||
|
|
@@ -51,25 +54,22 @@ class TestJvmSpec(val project: Project) { | |
| throw GradleException("testJvm property is blank") | ||
| } | ||
|
|
||
| // "stable" is calculated as the largest X found in JAVA_X_HOME | ||
| // "stable" is calculated as the largest Java version found via toolchains or JAVA_X_HOME | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. misc: I still do not like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not change it in this PR. |
||
| when (testJvm) { | ||
| "stable" -> { | ||
| val javaVersions = project.providers.environmentVariablesPrefixedBy("JAVA_").map { javaHomes -> | ||
| javaHomes | ||
| .filter { it.key.matches(Regex("^JAVA_[0-9]+_HOME$")) && it.key != "JAVA_26_HOME" } // JDK 26 is EA | ||
| .map { Regex("^JAVA_(\\d+)_HOME$").find(it.key)!!.groupValues[1].toInt() } | ||
| }.get() | ||
| val javaVersions = discoverJavaVersionsViaToolchains() | ||
| ?: discoverJavaVersionsViaEnvVars() | ||
|
|
||
| if (javaVersions.isEmpty()) { | ||
| throw GradleException("No valid JAVA_X_HOME environment variables found.") | ||
| throw GradleException("No Java installations found via toolchains or JAVA_X_HOME environment variables.") | ||
| } | ||
|
|
||
| javaVersions.max().toString() | ||
| } | ||
|
|
||
| else -> testJvm | ||
| } | ||
| }.map { project.logger.info("normalized testJvm: $it"); it } | ||
| }.map { project.logger.info("normalized testJvm: {}", it); it } | ||
|
|
||
| /** | ||
| * The home path of the test JVM. | ||
|
|
@@ -127,7 +127,7 @@ class TestJvmSpec(val project: Project) { | |
| """.trimIndent() | ||
| ) | ||
| } | ||
| }.map { project.logger.info("testJvm home path: $it"); it } | ||
| }.map { project.logger.info("testJvm home path: {}", it); it } | ||
|
|
||
| /** | ||
| * The Java launcher for the test JVM. | ||
|
|
@@ -145,7 +145,7 @@ class TestJvmSpec(val project: Project) { | |
| throw GradleException("Unable to find launcher for Java '$testJvm'. Does $TEST_JVM point to a JDK?") | ||
| }) | ||
| } | ||
| }.flatMap { it }.map { project.logger.info("testJvm launcher: ${it.executablePath}"); it } | ||
| }.flatMap { it }.map { project.logger.info("testJvm launcher: {}", it.executablePath); it } | ||
|
|
||
| private fun String.normalizeToJDKJavaHome(): Path { | ||
| val javaHome = project.file(this).toPath().toRealPath() | ||
|
|
@@ -159,4 +159,38 @@ class TestJvmSpec(val project: Project) { | |
| private val Project.javaToolchains: JavaToolchainService | ||
| get() = | ||
| extensions.getByName("javaToolchains") as JavaToolchainService | ||
|
|
||
| /** | ||
| * Discovers available Java versions via Gradle's internal JavaInstallationRegistry. | ||
| */ | ||
| private fun discoverJavaVersionsViaToolchains(): List<Int>? { | ||
| val registry = (project as ProjectInternal).services.get(JavaInstallationRegistry::class.java) | ||
| val versions = registry.toolchains().mapNotNull { installation -> | ||
| installation.metadata.languageVersion.majorVersion.toInt() | ||
| } | ||
|
|
||
| return if (versions.isNotEmpty()) { | ||
| project.logger.info("Discovered Java versions via toolchains: {}", versions) | ||
| versions | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Discovers available Java versions via JAVA_X_HOME environment variables. | ||
| * Fallback method when toolchain discovery is not available. | ||
| */ | ||
| private fun discoverJavaVersionsViaEnvVars(): List<Int> { | ||
| val versions = project.providers.environmentVariablesPrefixedBy("JAVA_").map { javaHomes -> | ||
| javaHomes | ||
| .filter { it.key.matches(Regex("^JAVA_[0-9]+_HOME$")) } | ||
| .mapNotNull { Regex("^JAVA_(\\d+)_HOME$").find(it.key)?.groupValues?.get(1)?.toIntOrNull() } | ||
| }.get() | ||
|
|
||
| if (versions.isNotEmpty()) { | ||
| project.logger.info("Discovered Java versions via JAVA_X_HOME env vars: {}", versions) | ||
| } | ||
| return versions | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.