neoforged / NeoForge

Neo Modding API for Minecraft, based on Forge
https://neoforged.net
Other
1.24k stars 179 forks source link

Enable Daemon JVM discovery to Java 21 #1692

Open sciwhiz12 opened 4 days ago

sciwhiz12 commented 4 days ago

This PR enables the Gradle Daemon JVM discovery feature and sets it to require and use a Java 21 JVM for the Gradle Daemon. For documentation's sake, the task is configured in the buildscript as to be an appropriate place to add a comment for it.

Due to the way that Gradle forks (or rather, doesn't fork) the compiler when the compile task's JVM differs from the Daemon's JVM, if the Gradle Daemon is not running on Java 21 (whether a lower or a higher version), trying to compile the NeoForge sources will result in an OutOfMemory error. (Ask @Technici4n on the details; I myself don't know much except of the results.)

To avoid this being a silent problem that is hard to diagnose and figure out for developers, the Daemon JVM discovery feature is configured to require and use a Java 21 JVM for the Daemon. (As of Gradle 8.10, Daemon JVM discovery does not do auto-provisioning in the same way as the Java toolchains feature does, so the developer has to install a Java 21 JVM if they do not have one already.)

neoforged-pr-publishing[bot] commented 4 days ago

Last commit published: 2975f498949299648443c3b6fe24916bd626ddb3.

PR Publishing ### The artifacts published by this PR: - :package: [`net.neoforged:neoforge:21.3.35-beta-pr-1692-daemon-jvm-discovery`](https://github.com/neoforged/NeoForge/packages/2315767) - :package: [`net.neoforged:testframework:21.3.35-beta-pr-1692-daemon-jvm-discovery`](https://github.com/neoforged/NeoForge/packages/2315768) ### Repository Declaration In order to use the artifacts published by the PR, add the following repository to your buildscript: ```gradle repositories { maven { name 'Maven for PR #1692' // https://github.com/neoforged/NeoForge/pull/1692 url 'https://prmaven.neoforged.net/NeoForge/pr1692' content { includeModule('net.neoforged', 'neoforge') includeModule('net.neoforged', 'testframework') } } } ``` ### MDK installation In order to setup a MDK using the latest PR version, run the following commands in a terminal. The script works on both *nix and Windows as long as you have the JDK `bin` folder on the path. The script will clone the MDK in a folder named `NeoForge-pr1692`. On Powershell you will need to remove the `-L` flag from the `curl` invocation. ```sh mkdir NeoForge-pr1692 cd NeoForge-pr1692 curl -L https://prmaven.neoforged.net/NeoForge/pr1692/net/neoforged/neoforge/21.3.35-beta-pr-1692-daemon-jvm-discovery/mdk-pr1692.zip -o mdk.zip jar xf mdk.zip rm mdk.zip || del mdk.zip ``` To test a production environment, you can download the installer from [here](https://prmaven.neoforged.net/NeoForge/pr1692/net.neoforged/neoforge/21.3.35-beta-pr-1692-daemon-jvm-discovery/neoforge-21.3.35-beta-pr-1692-daemon-jvm-discovery-installer.jar).
lukebemish commented 4 days ago

Any reason you can't just do

options.fork = true

If the issue is gradle failing to fork the JVM? (And then setting the forked memory if necessary? As in, it is necessary, set the compiler memory by forked jvm settings and make it always fork and it'll be fine)

Daemon toolchain discovery seems like overkill here when importing the project when only, say, J23 is available should work fine and download a J21 javac via toolchains -- but with a daemon toolchain set, this would fail outright if you don't have J21 locally, instead of letting it be discovered via foojay (in other words, it removes all benefits of project level toolchains and foojay)