Skip to content

Conversation

@ZZZank
Copy link
Contributor

@ZZZank ZZZank commented Nov 2, 2025

JVMDowngrader provides more feature than Jabel. In addition to modern Java syntax support, JVMDwongrader (JVMDG) will also allow us to use members introduced on modern Java version, e.g. List.of() and "someStr".lines().

This buildscript natively supports running client/server on Java 17 and Java 21, but for the sake of testing, I made some extra effort to apply JVMDG to normal runClient and runServer task, allowing you to test Java 8 compatibility without having to build jar and test in production environment.

I made some tests, and can confirm build/runClient/runServer is working for me.

Example for build:

Example.java in source file:

import java.util.ArrayList;
import java.util.List;

public class Example {
    public static void main(String[] args) {
        var j11lines = "wowww".lines();
        if (List.of() instanceof ArrayList<Object> arrayList) {
            arrayList.addAll(j11lines.toList());
        }
    }
}

Example.class in built jar (bogosorter-1.4.11.jar):

import bogosorter.xyz.wagyourtail.jvmdg.j16.stub.java_base.J_U_S_Stream;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

public class Example {
    public static void main(String[] args) {
        Stream<String> j11lines = jvmdg$inlined$lines("wowww");
        List var3 = jvmdg$inlined$of();
        if (var3 instanceof ArrayList) {
            ArrayList<Object> arrayList = (ArrayList)var3;
            arrayList.addAll(J_U_S_Stream.toList(j11lines));
        }
    }

    // $FF: synthetic method
    @Stub(ref = @Ref("Ljava/util/List;"))
    private static <E> List<E> jvmdg$inlined$of() {
        return Collections.emptyList();
    }

    // $FF: synthetic method
    @Stub
    private static Stream<String> jvmdg$inlined$lines(String str) {
        return (new BufferedReader(new StringReader(str))).lines();
    }
}

You can ignore the @Ref and @Stub annotation, they are invisible at runtime

@MCTian-mi
Copy link
Contributor

Seems RFG hardcoded RunMinecraftTasks to accept the output files of Jar task into the classpath.

        taskRunClient = project.getTasks().register("runClient", RunMinecraftTask.class, Distribution.CLIENT);
        final TaskProvider<?> taskJar = project.getTasks().named("jar");
        final Configuration runtimeClasspathCfg = project.getConfigurations()
                .getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
        final Configuration compileClasspathCfg = project.getConfigurations()
                .getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
        taskRunClient.configure(task -> {
            task.setup(project);
            task.setGroup(TASK_GROUP_USER);
            task.setDescription("Runs the deobfuscated client with your mod");
            task.dependsOn(
                    launcherSources.getClassesTaskName(),
                    mcTasks.getTaskDownloadVanillaAssets(),
                    taskPackagePatchedMc,
                    "jar");

            task.getUsername().set(mcExt.getUsername());
            task.getUserUUID().set(mcExt.getUserUUID());
            task.classpath(taskPackageMcLauncher);
            task.classpath(taskPackagePatchedMc);
            task.classpath(patchedConfiguration);
            task.classpath(taskJar);
            task.classpath(runtimeClasspathCfg);
            task.getMainClass().set("GradleStart");
        });

Idk how it managed to work on your machine™, but you should probably replace that with the output files from shadeDowngradedApi task. Here's what I have for sussypatches:

tasks.withType(JavaExec).named { it.contains('runClient') || it.contains('runServer') }.configureEach {
    dependsOn(shadeDowngradedApi)
    classpath = classpath - layout.files(jar) + layout.files(shadeDowngradedApi)
}

The name check here is mostly for compatibility with enableJava17RunTasks property in buildscript.properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants