Skip to content

Commit

Permalink
Add a Gradle property to override the runtime java compat version. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 authored Sep 26, 2024
1 parent 5b44b25 commit bc9ce58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,23 @@ private void provideServerLibraries() {
}

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);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/fabricmc/loom/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public static final class Properties {
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 {
Expand Down

0 comments on commit bc9ce58

Please sign in to comment.