Build: Keep Java 8 output while compiling 26.2 sources

- Compile main sources with --release 8

- Move record-dependent v26_2 input classes to a separate source set

- Use a JDK 25 toolchain for that source set, still emitting class version 52

- Fix the Injector PrintStream charset constructor for Java 8
This commit is contained in:
xiaozhou233 committed 2026-11-07 17:01:36 +08:00
1 parent a84b04877d
commit c8e23c5d1c
3 files changed
+37 -4

No files matched your search

@@ -13,17 +13,17 @@ public class Main {
public static String orangexPath = new File(System.getProperty("user.home") + "/.orangex").getAbsolutePath();
private static int pid = -1;
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
System.setOut(new PrintStream(
new FileOutputStream(FileDescriptor.out),
true,
StandardCharsets.UTF_8
StandardCharsets.UTF_8.name()
));
System.setErr(new PrintStream(
new FileOutputStream(FileDescriptor.err),
true,
StandardCharsets.UTF_8
StandardCharsets.UTF_8.name()
));
System.out.println("================");
+33
View File
@@ -37,9 +37,42 @@ dependencies {
// the API whose native methods are not registered.
}
// The 26.2 input classes import game classes that are records / class-file
// version 69, so they cannot be compiled with --release 8. Keep them in a
// separate source set compiled by JDK 25, but still emit Java 8 bytecode so a
// 1.8.9 JVM can load the rest of the jar.
sourceSets {
main {
java {
exclude 'cn/xiaozhou233/orangex/input/v26_2/**'
}
}
v26_2 {
java {
srcDir 'src/main/java'
include 'cn/xiaozhou233/orangex/input/v26_2/**'
}
compileClasspath += sourceSets.main.output
compileClasspath += configurations.compileClasspath
}
}
tasks.named('compileV26_2Java', JavaCompile).configure {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(25)
}
// No --release: the JDK 25 platform classpath is needed to resolve records
// from Minecraft26.2.jar, while -source/-target 8 keeps the output loadable
// by Java 8.
options.release = null
options.encoding = 'UTF-8'
}
tasks.named('shadowJar') {
destinationDirectory = rootProject.layout.projectDirectory.dir('out/tmp')
archiveFileName = "${project.name}.jar"
dependsOn tasks.named('v26_2Classes')
from sourceSets.v26_2.output
}
shadowJar {
+1 -1
View File
@@ -63,7 +63,7 @@ subprojects {
options.encoding = 'UTF-8'
if (JavaVersion.current().isJava9Compatible()) {
// Fail fast if a post-Java-8 API is used.
options.release = 25
options.release = 8
}
}
}