Add a Gradle property to override the runtime java compat version. (#1178)

This commit is contained in:
modmuss
2024-09-26 19:03:53 +01:00
committed by GitHub
parent 5b44b25066
commit bc9ce581e4
2 changed files with 19 additions and 1 deletions

View File

@@ -119,10 +119,23 @@ public class MinecraftLibraryProvider {
}
private List<Library> processLibraries(List<Library> libraries) {
final LibraryContext libraryContext = new LibraryContext(minecraftProvider.getVersionInfo(), JavaVersion.current());
final LibraryContext libraryContext = new LibraryContext(minecraftProvider.getVersionInfo(), getTargetRuntimeJavaVersion());
return processorManager.processLibraries(libraries, libraryContext);
}
private JavaVersion getTargetRuntimeJavaVersion() {
final Object property = project.findProperty(Constants.Properties.RUNTIME_JAVA_COMPATIBILITY_VERSION);
if (property != null) {
// This is very much a last ditch effort to allow users to set the runtime java version
// It's not recommended and will likely cause support confusion if it has been changed without good reason.
project.getLogger().warn("Runtime java compatibility version has manually been set to: %s".formatted(property));
return JavaVersion.toVersion(property);
}
return JavaVersion.current();
}
private void applyClientLibrary(Library library) {
switch (library.target()) {
case COMPILE -> addLibrary(Constants.Configurations.MINECRAFT_CLIENT_COMPILE_LIBRARIES, library);

View File

@@ -134,6 +134,11 @@ public class Constants {
public static final String LIBRARY_PROCESSORS = "fabric.loom.libraryProcessors";
@ApiStatus.Experimental
public static final String SANDBOX = "fabric.loom.experimental.sandbox";
/**
* When set the version of java that will be assumed that the game will run on, this defaults to the current java version.
* Only set this when you have a good reason to do so, the default should be fine for almost all cases.
*/
public static final String RUNTIME_JAVA_COMPATIBILITY_VERSION = "fabric.loom.runtimeJavaCompatibilityVersion";
}
public static final class Manifest {