From c8e78a2bed48271fab3c0df0757f6367161fbd54 Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:35:26 +0100 Subject: [PATCH 01/13] Fix root project name for Eclipse on Windows (#1682) Co-authored-by: Marc Hermans --- settings.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 74b177945e1..4049a3edc6f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,10 @@ plugins { id 'net.neoforged.gradle.platform' version '7.0.163' } -rootProject.name = rootDir.name +if (rootProject.name.toLowerCase() == "neoforge") { + // Solve name clashes between projects/neoforge and the rootProject for Eclipse. + rootProject.name = "NeoForge-Root" +} dynamicProjects { include ':base' From e882664c71533293427f4a245952c5664548f86a Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+technici4n@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:27:57 +0100 Subject: [PATCH 02/13] Use an in-tree Gradle plugin instead of an external Gradle Plugin to make version-specific changes easier (#1485) Co-authored-by: Sebastian Hartte --- .github/workflows/check-local-changes.yml | 2 +- build.gradle | 19 +- buildSrc/README.md | 81 +++ buildSrc/build.gradle | 23 + buildSrc/settings.gradle | 0 .../neoforge.formatting-conventions.gradle | 14 +- .../neodev/ApplyAccessTransformer.java | 72 +++ .../net/neoforged/neodev/ApplyPatches.java | 79 +++ .../neodev/CreateCleanArtifacts.java | 36 ++ .../neoforged/neodev/CreateUserDevConfig.java | 203 +++++++ .../neodev/GenerateBinaryPatches.java | 70 +++ .../neodev/GenerateSourcePatches.java | 55 ++ .../neoforged/neodev/NeoDevBasePlugin.java | 24 + .../neodev/NeoDevConfigurations.java | 204 +++++++ .../net/neoforged/neodev/NeoDevExtension.java | 35 ++ .../neoforged/neodev/NeoDevExtraPlugin.java | 79 +++ .../net/neoforged/neodev/NeoDevPlugin.java | 540 ++++++++++++++++++ .../neoforged/neodev/NeoDevTestExtension.java | 30 + .../java/net/neoforged/neodev/RemapJar.java | 53 ++ .../main/java/net/neoforged/neodev/Tools.java | 53 ++ .../neodev/installer/CreateArgsFile.java | 126 ++++ .../installer/CreateInstallerProfile.java | 230 ++++++++ .../installer/CreateLauncherProfile.java | 130 +++++ .../neodev/installer/IdentifiedFile.java | 48 ++ .../neodev/installer/InstallerProcessor.java | 19 + .../neoforged/neodev/installer/Library.java | 3 + .../neodev/installer/LibraryArtifact.java | 7 + .../neodev/installer/LibraryCollector.java | 174 ++++++ .../neodev/installer/LibraryDownload.java | 4 + .../neodev/utils/DependencyUtils.java | 84 +++ .../net/neoforged/neodev/utils/FileUtils.java | 72 +++ .../neodev/utils/MavenIdentifier.java | 13 + coremods/build.gradle | 9 - coremods/settings.gradle | 8 + gradle.properties | 23 +- gradle/wrapper/gradle-wrapper.properties | 2 +- projects/base/build.gradle | 16 +- projects/neoforge/build.gradle | 376 ++++-------- settings.gradle | 30 +- testframework/build.gradle | 27 +- tests/build.gradle | 144 +++-- 41 files changed, 2832 insertions(+), 385 deletions(-) create mode 100644 buildSrc/README.md create mode 100644 buildSrc/settings.gradle create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/ApplyAccessTransformer.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/ApplyPatches.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/CreateCleanArtifacts.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/GenerateBinaryPatches.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/GenerateSourcePatches.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtension.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtraPlugin.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/NeoDevTestExtension.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/RemapJar.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/Tools.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/IdentifiedFile.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/InstallerProcessor.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/Library.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryArtifact.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryDownload.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/utils/FileUtils.java create mode 100644 buildSrc/src/main/java/net/neoforged/neodev/utils/MavenIdentifier.java create mode 100644 coremods/settings.gradle diff --git a/.github/workflows/check-local-changes.yml b/.github/workflows/check-local-changes.yml index ef101ceacdf..0609d67e89d 100644 --- a/.github/workflows/check-local-changes.yml +++ b/.github/workflows/check-local-changes.yml @@ -41,7 +41,7 @@ jobs: run: ./gradlew generatePackageInfos - name: Gen patches - run: ./gradlew :neoforge:unpackSourcePatches + run: ./gradlew :neoforge:genPatches - name: Run datagen with Gradle run: ./gradlew :neoforge:runData :tests:runData diff --git a/build.gradle b/build.gradle index 6c46fb5ba61..fbc90b7d61c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ import java.util.regex.Pattern plugins { id 'net.neoforged.gradleutils' version '3.0.0' id 'com.diffplug.spotless' version '6.22.0' apply false - id 'net.neoforged.licenser' version '0.7.2' + id 'net.neoforged.licenser' version '0.7.5' id 'neoforge.formatting-conventions' id 'neoforge.versioning' } @@ -23,19 +23,22 @@ System.out.println("NeoForge version ${project.version}") allprojects { version rootProject.version group 'net.neoforged' - repositories { - mavenLocal() - } -} -subprojects { apply plugin: 'java' java.toolchain.languageVersion.set(JavaLanguageVersion.of(project.java_version)) } -repositories { - mavenCentral() +// Remove src/ sources from the root project. They are used in the neoforge subproject. +sourceSets { + main { + java { + srcDirs = [] + } + resources { + srcDirs = [] + } + } } // Put licenser here otherwise it tries to license all source sets including decompiled MC sources diff --git a/buildSrc/README.md b/buildSrc/README.md new file mode 100644 index 00000000000..2e63a427c06 --- /dev/null +++ b/buildSrc/README.md @@ -0,0 +1,81 @@ +# NeoForge Development Gradle Plugin + +## NeoForge Project Structure + +Before understanding the `buildSrc` plugin, one should understand the structure of the NeoForge Gradle project it is +applied to. + +The project consists of a project tree with the following structure: + +| Folder Path | Gradle Project Path | Applied Plugins | Description | +|------------------------------------------------------------------------|----------------------|:------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`/build.gradle`](../build.gradle) | `:` | — | The root project. Since this project is reused for Kits, the root project name is based on the checkout folder, which actually can lead to issues if it is called `NeoForge`. | +| [`/projects/neoforge/build.gradle`](../projects/neoforge/build.gradle) | `:neoforge` | [NeoDevPlugin](#neodevplugin) | The core NeoForge project, which produces the artifacts that will be published. | +| [`/projects/base/build.gradle`](../projects/base/build.gradle) | `:base` | [NeoDevBasePlugin](#neodevbaseplugin) | A utility project that contains the Minecraft sources without any NeoForge additions. Can be used to quickly compare what NeoForge has changed. | +| [`/tests/build.gradle`](../tests/build.gradle) | `:tests` | [NeoDevExtraPlugin](#neodevextraplugin) | Contains the game and unit tests for NeoForge. | +| [`/testframework/build.gradle`](../testframework/build.gradle) | `:testframework` | [MinecraftDependenciesPlugin](#minecraftdependenciesplugin) | A library providing support classes around writing game tests. | +| [`/coremods/build.gradle`](../coremods/build.gradle) | `:neoforge-coremods` | — | Java Bytecode transformers that are embedded into NeoForge as a nested Jar file. | +| + +## Plugins + +### NeoDevBasePlugin + +Sources: [NeoDevBasePlugin.java](src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java) + +Implicitly applies: [MinecraftDependenciesPlugin](#minecraftdependenciesplugin). + +Sets up a `setup` task that reuses code from [NeoDevPlugin](#neodevplugin) to decompile Minecraft and place the +decompiled sources in `projects/base/src/main/java`. + +### NeoDevPlugin + +Sources: [NeoDevPlugin.java](src/main/java/net/neoforged/neodev/NeoDevPlugin.java) + +Implicitly applies: [MinecraftDependenciesPlugin](#minecraftdependenciesplugin). + +This is the primary of this repository and is used to configure the `neoforge` subproject. + +#### Setup + +It creates a `setup` task that performs the following actions via various subtasks: + +- Decompile Minecraft using the [NeoForm Runtime](https://github.com/neoforged/neoformruntime) and Minecraft version specific [NeoForm data](https://github.com/neoforged/NeoForm). +- Applies [Access Transformers](../src/main/resources/META-INF/accesstransformer.cfg) to Minecraft sources. +- Applies [NeoForge patches](../patches) to Minecraft sources. Any rejects are saved to the `/rejects` folder in the repository for manual inspection. During updates to new versions, the task can be run with `-Pupdating=true` to apply patches more leniently. +- Unpacks the patched sources to `projects/neoforge/src/main/java`. + +#### Config Generation + +The plugin creates and configures the tasks to create various configuration files used downstream to develop +mods with this version of NeoForge ([CreateUserDevConfig](src/main/java/net/neoforged/neodev/CreateUserDevConfig.java)), or install it ([CreateInstallerProfile](src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java) and [CreateLauncherProfile](src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java)). + +A separate userdev profile is created for use by other subprojects in this repository. +The only difference is that it uses the FML launch types ending in `dev` rather than `userdev`. + +#### Patch Generation + +NeoForge injects its hooks into Minecraft by patching the decompiled source code. +Changes are made locally to the decompiled and patched source. +Since that source cannot be published, patches need to be generated before checking in. +The plugin configures the necessary task to do this +([GenerateSourcePatches](src/main/java/net/neoforged/neodev/GenerateSourcePatches.java)). + +The source patches are only used during development of NeoForge itself and development of mods that use Gradle plugins implementing the decompile/patch/recompile pipeline. +For use by the installer intended for players as well as Gradle plugins wanting to replicate the production artifacts more closely, binary patches are generated using the ([GenerateBinaryPatches](src/main/java/net/neoforged/neodev/GenerateBinaryPatches.java)) task. + +### NeoDevExtraPlugin + +Sources: [NeoDevExtraPlugin.java](src/main/java/net/neoforged/neodev/NeoDevExtraPlugin.java) + +This plugin can be applied to obtain a dependency on the `neoforge` project to depend on NeoForge including Minecraft +itself. Besides wiring up the dependency, it also creates run configurations based on the run-types defined in the +`neoforge` project. + +### MinecraftDependenciesPlugin + +This plugin is reused from [ModDevGradle](https://github.com/neoforged/ModDevGradle/). + +It sets up repositories and attributes such that +the [libraries that Minecraft itself depends upon](https://github.com/neoforged/GradleMinecraftDependencies) can be +used. diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 67840524598..6d0ce4c5af1 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,3 +1,26 @@ plugins { + id 'java-gradle-plugin' id 'groovy-gradle-plugin' } + +repositories { + gradlePluginPortal() + mavenCentral() + maven { + name = "NeoForged" + url = "https://maven.neoforged.net/releases" + content { + includeGroup "codechicken" + includeGroup "net.neoforged" + } + } +} + +dependencies { + // buildSrc is an includedbuild of the parent directory (gradle.parent) + // ../settings.gradle sets these version properties accordingly + implementation "net.neoforged:moddev-gradle:${gradle.parent.ext.moddevgradle_plugin_version}" + + implementation "com.google.code.gson:gson:${gradle.parent.ext.gson_version}" + implementation "io.codechicken:DiffPatch:${gradle.parent.ext.diffpatch_version}" +} diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 00000000000..e69de29bb2d diff --git a/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle b/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle index 0ba7b488525..e0f554b8205 100644 --- a/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle +++ b/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle @@ -2,9 +2,14 @@ import java.util.regex.Matcher project.plugins.apply('com.diffplug.spotless') -final generatePackageInfos = tasks.register('generatePackageInfos', Task) { - doLast { - fileTree('src/main/java').each { javaFile -> +abstract class GeneratePackageInfos extends DefaultTask { + @InputFiles + @PathSensitive(PathSensitivity.RELATIVE) + abstract ConfigurableFileCollection getFiles(); + + @TaskAction + void generatePackageInfos() { + getFiles().each { javaFile -> def packageInfoFile = new File(javaFile.parent, 'package-info.java') if (!packageInfoFile.exists()) { def pkgName = javaFile.toString().replaceAll(Matcher.quoteReplacement(File.separator), '/') @@ -27,6 +32,9 @@ final generatePackageInfos = tasks.register('generatePackageInfos', Task) { } } } +final generatePackageInfos = tasks.register('generatePackageInfos', GeneratePackageInfos) { + it.files.from fileTree("src/main/java") +} spotless { java { diff --git a/buildSrc/src/main/java/net/neoforged/neodev/ApplyAccessTransformer.java b/buildSrc/src/main/java/net/neoforged/neodev/ApplyAccessTransformer.java new file mode 100644 index 00000000000..7131cc8fddc --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/ApplyAccessTransformer.java @@ -0,0 +1,72 @@ +package net.neoforged.neodev; + +import net.neoforged.neodev.utils.FileUtils; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Classpath; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.Internal; +import org.gradle.api.tasks.JavaExec; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +import javax.inject.Inject; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; + +/** + * Runs JavaSourceTransformer to apply + * access transformers to the Minecraft source code for extending the access level of existing classes/methods/etc. + *

+ * Note that at runtime, FML also applies access transformers. + */ +abstract class ApplyAccessTransformer extends JavaExec { + @InputFile + public abstract RegularFileProperty getInputJar(); + + @InputFile + public abstract RegularFileProperty getAccessTransformer(); + + @Input + public abstract Property getValidate(); + + @OutputFile + public abstract RegularFileProperty getOutputJar(); + + // Used to give JST more information about the classes. + @Classpath + public abstract ConfigurableFileCollection getLibraries(); + + @Internal + public abstract RegularFileProperty getLibrariesFile(); + + @Inject + public ApplyAccessTransformer() {} + + @Override + @TaskAction + public void exec() { + try { + FileUtils.writeLinesSafe( + getLibrariesFile().getAsFile().get().toPath(), + getLibraries().getFiles().stream().map(File::getAbsolutePath).toList(), + StandardCharsets.UTF_8); + } catch (IOException exception) { + throw new UncheckedIOException("Failed to write libraries for JST.", exception); + } + + args( + "--enable-accesstransformers", + "--access-transformer", getAccessTransformer().getAsFile().get().getAbsolutePath(), + "--access-transformer-validation", getValidate().get() ? "error" : "log", + "--libraries-list", getLibrariesFile().getAsFile().get().getAbsolutePath(), + getInputJar().getAsFile().get().getAbsolutePath(), + getOutputJar().getAsFile().get().getAbsolutePath()); + + super.exec(); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/ApplyPatches.java b/buildSrc/src/main/java/net/neoforged/neodev/ApplyPatches.java new file mode 100644 index 00000000000..037e5f9bf61 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/ApplyPatches.java @@ -0,0 +1,79 @@ +package net.neoforged.neodev; + +import io.codechicken.diffpatch.cli.PatchOperation; +import io.codechicken.diffpatch.util.Input.MultiInput; +import io.codechicken.diffpatch.util.Output.MultiOutput; +import io.codechicken.diffpatch.util.PatchMode; +import org.gradle.api.DefaultTask; +import org.gradle.api.Project; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputDirectory; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.OutputDirectory; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.PathSensitive; +import org.gradle.api.tasks.PathSensitivity; +import org.gradle.api.tasks.TaskAction; +import org.gradle.work.DisableCachingByDefault; + +import javax.inject.Inject; +import java.io.IOException; + +/** + * Applies Java source patches to a source jar and produces a patched source jar as an output. + * It can optionally store rejected hunks into a given folder, which is primarily used for updating + * when the original sources changed and some hunks are expected to fail. + */ +@DisableCachingByDefault(because = "Not worth caching") +abstract class ApplyPatches extends DefaultTask { + @InputFile + public abstract RegularFileProperty getOriginalJar(); + + @InputDirectory + @PathSensitive(PathSensitivity.NONE) + public abstract DirectoryProperty getPatchesFolder(); + + @OutputFile + public abstract RegularFileProperty getPatchedJar(); + + @OutputDirectory + public abstract DirectoryProperty getRejectsFolder(); + + @Input + protected abstract Property getIsUpdating(); + + @Inject + public ApplyPatches(Project project) { + getIsUpdating().set(project.getProviders().gradleProperty("updating").map(Boolean::parseBoolean).orElse(false)); + } + + @TaskAction + public void applyPatches() throws IOException { + var isUpdating = getIsUpdating().get(); + + var builder = PatchOperation.builder() + .logTo(getLogger()::lifecycle) + .baseInput(MultiInput.detectedArchive(getOriginalJar().get().getAsFile().toPath())) + .patchesInput(MultiInput.folder(getPatchesFolder().get().getAsFile().toPath())) + .patchedOutput(MultiOutput.detectedArchive(getPatchedJar().get().getAsFile().toPath())) + .rejectsOutput(MultiOutput.folder(getRejectsFolder().get().getAsFile().toPath())) + .mode(isUpdating ? PatchMode.FUZZY : PatchMode.ACCESS) + .aPrefix("a/") + .bPrefix("b/") + .level(isUpdating ? io.codechicken.diffpatch.util.LogLevel.ALL : io.codechicken.diffpatch.util.LogLevel.WARN) + .minFuzz(0.9f); // The 0.5 default in DiffPatch is too low. + + var result = builder.build().operate(); + + int exit = result.exit; + if (exit != 0 && exit != 1) { + throw new RuntimeException("DiffPatch failed with exit code: " + exit); + } + if (exit != 0 && !isUpdating) { + throw new RuntimeException("Patches failed to apply."); + } + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/CreateCleanArtifacts.java b/buildSrc/src/main/java/net/neoforged/neodev/CreateCleanArtifacts.java new file mode 100644 index 00000000000..2cb2e89ade2 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/CreateCleanArtifacts.java @@ -0,0 +1,36 @@ +package net.neoforged.neodev; + +import net.neoforged.nfrtgradle.CreateMinecraftArtifacts; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.OutputFile; + +import javax.inject.Inject; + +abstract class CreateCleanArtifacts extends CreateMinecraftArtifacts { + @OutputFile + abstract RegularFileProperty getCleanClientJar(); + + @OutputFile + abstract RegularFileProperty getRawServerJar(); + + @OutputFile + abstract RegularFileProperty getCleanServerJar(); + + @OutputFile + abstract RegularFileProperty getCleanJoinedJar(); + + @OutputFile + abstract RegularFileProperty getMergedMappings(); + + @Inject + public CreateCleanArtifacts() { + getAdditionalResults().put("node.stripClient.output.output", getCleanClientJar().getAsFile()); + getAdditionalResults().put("node.downloadServer.output.output", getRawServerJar().getAsFile()); + getAdditionalResults().put("node.stripServer.output.output", getCleanServerJar().getAsFile()); + getAdditionalResults().put("node.rename.output.output", getCleanJoinedJar().getAsFile()); + getAdditionalResults().put("node.mergeMappings.output.output", getMergedMappings().getAsFile()); + + // TODO: does anyone care about this? they should be contained in the client mappings + //"--write-result", "node.downloadServerMappings.output.output:" + getServerMappings().get().getAsFile().getAbsolutePath() + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java new file mode 100644 index 00000000000..ab24c91d4d8 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java @@ -0,0 +1,203 @@ +package net.neoforged.neodev; + +import com.google.gson.GsonBuilder; +import net.neoforged.neodev.utils.FileUtils; +import org.gradle.api.DefaultTask; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +import javax.inject.Inject; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Creates the userdev configuration file used by the various Gradle plugins used to develop + * mods for NeoForge, such as Architectury Loom, + * ModDevGradle + * or NeoGradle. + */ +abstract class CreateUserDevConfig extends DefaultTask { + @Inject + public CreateUserDevConfig() {} + + /** + * Toggles the launch type written to the userdev configuration between *dev and *userdev. + */ + @Input + abstract Property getForNeoDev(); + + @Input + abstract Property getFmlVersion(); + + @Input + abstract Property getMinecraftVersion(); + + @Input + abstract Property getNeoForgeVersion(); + + @Input + abstract Property getRawNeoFormVersion(); + + @Input + abstract ListProperty getLibraries(); + + @Input + abstract ListProperty getModules(); + + @Input + abstract ListProperty getTestLibraries(); + + @Input + abstract ListProperty getIgnoreList(); + + @Input + abstract Property getBinpatcherGav(); + + @OutputFile + abstract RegularFileProperty getUserDevConfig(); + + @TaskAction + public void writeUserDevConfig() throws IOException { + var config = new UserDevConfig( + 2, + "net.neoforged:neoform:%s-%s@zip".formatted(getMinecraftVersion().get(), getRawNeoFormVersion().get()), + "ats/", + "joined.lzma", + new BinpatcherConfig( + getBinpatcherGav().get(), + List.of("--clean", "{clean}", "--output", "{output}", "--apply", "{patch}")), + "patches/", + "net.neoforged:neoforge:%s:sources".formatted(getNeoForgeVersion().get()), + "net.neoforged:neoforge:%s:universal".formatted(getNeoForgeVersion().get()), + getLibraries().get(), + getTestLibraries().get(), + new LinkedHashMap<>(), + getModules().get()); + + for (var runType : RunType.values()) { + var launchTarget = switch (runType) { + case CLIENT -> "forgeclient"; + case DATA -> "forgedata"; + case GAME_TEST_SERVER, SERVER -> "forgeserver"; + case JUNIT -> "forgejunit"; + } + (getForNeoDev().get() ? "dev" : "userdev"); + + List args = new ArrayList<>(); + Collections.addAll(args, + "--launchTarget", launchTarget); + + if (runType == RunType.CLIENT || runType == RunType.JUNIT) { + // TODO: this is copied from NG but shouldn't it be the MC version? + Collections.addAll(args, + "--version", getNeoForgeVersion().get()); + } + + if (runType == RunType.CLIENT || runType == RunType.DATA || runType == RunType.JUNIT) { + Collections.addAll(args, + "--assetIndex", "{asset_index}", + "--assetsDir", "{assets_root}"); + } + + Collections.addAll(args, + "--gameDir", ".", + "--fml.fmlVersion", getFmlVersion().get(), + "--fml.mcVersion", getMinecraftVersion().get(), + "--fml.neoForgeVersion", getNeoForgeVersion().get(), + "--fml.neoFormVersion", getRawNeoFormVersion().get()); + + Map systemProperties = new LinkedHashMap<>(); + systemProperties.put("java.net.preferIPv6Addresses", "system"); + systemProperties.put("ignoreList", String.join(",", getIgnoreList().get())); + systemProperties.put("legacyClassPath.file", "{minecraft_classpath_file}"); + + if (runType == RunType.CLIENT || runType == RunType.GAME_TEST_SERVER) { + systemProperties.put("neoforge.enableGameTest", "true"); + + if (runType == RunType.GAME_TEST_SERVER) { + systemProperties.put("neoforge.gameTestServer", "true"); + } + } + + config.runs().put(runType.jsonName, new UserDevRunType( + runType != RunType.JUNIT, + "cpw.mods.bootstraplauncher.BootstrapLauncher", + args, + List.of( + "-p", "{modules}", + "--add-modules", "ALL-MODULE-PATH", + "--add-opens", "java.base/java.util.jar=cpw.mods.securejarhandler", + "--add-opens", "java.base/java.lang.invoke=cpw.mods.securejarhandler", + "--add-exports", "java.base/sun.security.util=cpw.mods.securejarhandler", + "--add-exports", "jdk.naming.dns/com.sun.jndi.dns=java.naming"), + runType == RunType.CLIENT || runType == RunType.JUNIT, + runType == RunType.GAME_TEST_SERVER || runType == RunType.SERVER, + runType == RunType.DATA, + runType == RunType.CLIENT || runType == RunType.GAME_TEST_SERVER, + runType == RunType.JUNIT, + Map.of( + "MOD_CLASSES", "{source_roots}"), + systemProperties + )); + } + + FileUtils.writeStringSafe( + getUserDevConfig().getAsFile().get().toPath(), + new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(config), + // TODO: Not sure what this should be? Most likely the file is ASCII. + StandardCharsets.UTF_8); + } + + private enum RunType { + CLIENT("client"), + DATA("data"), + GAME_TEST_SERVER("gameTestServer"), + SERVER("server"), + JUNIT("junit"); + + private final String jsonName; + + RunType(String jsonName) { + this.jsonName = jsonName; + } + } +} + +record UserDevConfig( + int spec, + String mcp, + String ats, + String binpatches, + BinpatcherConfig binpatcher, + String patches, + String sources, + String universal, + List libraries, + List testLibraries, + Map runs, + List modules) {} + +record BinpatcherConfig( + String version, + List args) {} + +record UserDevRunType( + boolean singleInstance, + String main, + List args, + List jvmArgs, + boolean client, + boolean server, + boolean dataGenerator, + boolean gameTest, + boolean unitTest, + Map env, + Map props) {} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/GenerateBinaryPatches.java b/buildSrc/src/main/java/net/neoforged/neodev/GenerateBinaryPatches.java new file mode 100644 index 00000000000..35a06a8c33f --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/GenerateBinaryPatches.java @@ -0,0 +1,70 @@ +package net.neoforged.neodev; + +import org.gradle.api.GradleException; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputDirectory; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.JavaExec; +import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputFile; + +import javax.inject.Inject; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +abstract class GenerateBinaryPatches extends JavaExec { + @Inject + public GenerateBinaryPatches() {} + + /** + * The jar file containing classes in the base state. + */ + @InputFile + abstract RegularFileProperty getCleanJar(); + + /** + * The jar file containing classes in the desired target state. + */ + @InputFile + abstract RegularFileProperty getPatchedJar(); + + @InputFile + abstract RegularFileProperty getMappings(); + + /** + * This directory of patch files for the Java sources is used as a hint to only diff class files that + * supposedly have changed. If it is not set, the tool will diff every .class file instead. + */ + @InputDirectory + @Optional + abstract DirectoryProperty getSourcePatchesFolder(); + + /** + * The location where the LZMA compressed binary patches are written to. + */ + @OutputFile + abstract RegularFileProperty getOutputFile(); + + @Override + public void exec() { + args("--clean", getCleanJar().get().getAsFile().getAbsolutePath()); + args("--dirty", getPatchedJar().get().getAsFile().getAbsolutePath()); + args("--srg", getMappings().get().getAsFile().getAbsolutePath()); + if (getSourcePatchesFolder().isPresent()) { + args("--patches", getSourcePatchesFolder().get().getAsFile().getAbsolutePath()); + } + args("--output", getOutputFile().get().getAsFile().getAbsolutePath()); + + var logFile = new File(getTemporaryDir(), "console.log"); + try (var out = new BufferedOutputStream(new FileOutputStream(logFile))) { + getLogger().info("Logging binpatcher console output to {}", logFile.getAbsolutePath()); + setStandardOutput(out); + super.exec(); + } catch (IOException e) { + throw new GradleException("Failed to create binary patches.", e); + } + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/GenerateSourcePatches.java b/buildSrc/src/main/java/net/neoforged/neodev/GenerateSourcePatches.java new file mode 100644 index 00000000000..c6e1c7e7302 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/GenerateSourcePatches.java @@ -0,0 +1,55 @@ +package net.neoforged.neodev; + +import io.codechicken.diffpatch.cli.CliOperation; +import io.codechicken.diffpatch.cli.DiffOperation; +import io.codechicken.diffpatch.util.Input.MultiInput; +import io.codechicken.diffpatch.util.Output.MultiOutput; +import org.gradle.api.DefaultTask; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputDirectory; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.PathSensitive; +import org.gradle.api.tasks.PathSensitivity; +import org.gradle.api.tasks.TaskAction; + +import javax.inject.Inject; +import java.io.IOException; + +abstract class GenerateSourcePatches extends DefaultTask { + @InputFile + public abstract RegularFileProperty getOriginalJar(); + + @InputDirectory + @PathSensitive(PathSensitivity.RELATIVE) + public abstract DirectoryProperty getModifiedSources(); + + @OutputFile + public abstract RegularFileProperty getPatchesJar(); + + @Inject + public GenerateSourcePatches() {} + + @TaskAction + public void generateSourcePatches() throws IOException { + var builder = DiffOperation.builder() + .logTo(getLogger()::lifecycle) + .baseInput(MultiInput.detectedArchive(getOriginalJar().get().getAsFile().toPath())) + .changedInput(MultiInput.folder(getModifiedSources().get().getAsFile().toPath())) + .patchesOutput(MultiOutput.detectedArchive(getPatchesJar().get().getAsFile().toPath())) + .autoHeader(true) + .level(io.codechicken.diffpatch.util.LogLevel.WARN) + .summary(false) + .aPrefix("a/") + .bPrefix("b/") + .lineEnding("\n"); + + CliOperation.Result result = builder.build().operate(); + + int exit = result.exit; + if (exit != 0 && exit != 1) { + throw new RuntimeException("DiffPatch failed with exit code: " + exit); + } + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java new file mode 100644 index 00000000000..7680fffa9f7 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java @@ -0,0 +1,24 @@ +package net.neoforged.neodev; + +import net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin; +import net.neoforged.nfrtgradle.CreateMinecraftArtifacts; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.tasks.Sync; + +public class NeoDevBasePlugin implements Plugin { + @Override + public void apply(Project project) { + // These plugins allow us to declare dependencies on Minecraft libraries needed to compile the official sources + project.getPlugins().apply(MinecraftDependenciesPlugin.class); + + var createSources = NeoDevPlugin.configureMinecraftDecompilation(project); + + project.getTasks().register("setup", Sync.class, task -> { + task.setGroup(NeoDevPlugin.GROUP); + task.setDescription("Replaces the contents of the base project sources with the unpatched, decompiled Minecraft source code."); + task.from(project.zipTree(createSources.flatMap(CreateMinecraftArtifacts::getSourcesArtifact))); + task.into(project.file("src/main/java/")); + }); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java new file mode 100644 index 00000000000..35eb5b570df --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java @@ -0,0 +1,204 @@ +package net.neoforged.neodev; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.ConfigurationContainer; +import org.gradle.api.attributes.Bundling; +import org.gradle.api.plugins.JavaPlugin; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Helper class to keep track of the many {@link Configuration}s used for the {@code neoforge} project. + */ +class NeoDevConfigurations { + static NeoDevConfigurations createAndSetup(Project project) { + return new NeoDevConfigurations(project); + } + + // + // Configurations against which dependencies should be declared ("dependency scopes"). + // + + /** + * Only the NeoForm data zip and the dependencies to run NeoForm. + * Does not contain the dependencies to run vanilla Minecraft. + */ + final Configuration neoFormData; + /** + * Only the NeoForm dependencies. + * These are the dependencies required to run NeoForm-decompiled Minecraft. + * Does not contain the dependencies to run the NeoForm process itself. + */ + final Configuration neoFormDependencies; + /** + * Libraries used by NeoForge at compilation and runtime. + * These will end up on the MC-BOOTSTRAP module layer. + */ + final Configuration libraries; + /** + * Libraries used by NeoForge at compilation and runtime that need to be placed on the jvm's module path to end up in the boot layer. + * Currently, this only contains the few dependencies that are needed to create the MC-BOOTSTRAP module layer. + * (i.e. BootstrapLauncher and its dependencies). + */ + final Configuration moduleLibraries; + /** + * Libraries that should be accessible in mod development environments at compilation time only. + * Currently, this is only used for MixinExtras, which is already available at runtime via JiJ in the NeoForge universal jar. + */ + final Configuration userdevCompileOnly; + /** + * Libraries that should be accessible at runtime in unit tests. + * Currently, this only contains the fml-junit test fixtures. + */ + final Configuration userdevTestFixtures; + + // + // Resolvable configurations. + // + + /** + * Resolved {@link #neoFormData}. + * This is used to add NeoForm to the installer libraries. + * Only the zip is used (for the mappings), not the NeoForm tools, so it's not transitive. + */ + final Configuration neoFormDataOnly; + /** + * Resolvable {@link #neoFormDependencies}. + */ + final Configuration neoFormClasspath; + /** + * Resolvable {@link #moduleLibraries}. + */ + final Configuration modulePath; + /** + * Userdev dependencies (written to a json file in the userdev jar). + * This should contain all of NeoForge's additional dependencies for userdev, + * but does not need to include Minecraft or NeoForm's libraries. + */ + final Configuration userdevClasspath; + /** + * Resolvable {@link #userdevCompileOnly}, to add these entries to the ignore list of BootstrapLauncher. + */ + final Configuration userdevCompileOnlyClasspath; + /** + * Resolvable {@link #userdevTestFixtures}, to write it in the userdev jar. + */ + final Configuration userdevTestClasspath; + /** + * Libraries that need to be added to the classpath when launching NeoForge through the launcher. + * This contains all dependencies added by NeoForge, but does not include all of Minecraft's libraries. + * This is also used to produce the legacy classpath file for server installs. + */ + final Configuration launcherProfileClasspath; + + // + // The configurations for resolution only are declared in the build.gradle file. + // + + /** + * To download each executable tool, we use a resolvable configuration. + * These configurations support both declaration and resolution. + */ + final Map toolClasspaths; + + private static Configuration dependencyScope(ConfigurationContainer configurations, String name) { + return configurations.create(name, configuration -> { + configuration.setCanBeConsumed(false); + configuration.setCanBeResolved(false); + }); + } + + private static Configuration resolvable(ConfigurationContainer configurations, String name) { + return configurations.create(name, configuration -> { + configuration.setCanBeConsumed(false); + configuration.setCanBeDeclared(false); + }); + } + + private NeoDevConfigurations(Project project) { + var configurations = project.getConfigurations(); + + neoFormData = dependencyScope(configurations, "neoFormData"); + neoFormDependencies = dependencyScope(configurations, "neoFormDependencies"); + libraries = dependencyScope(configurations, "libraries"); + moduleLibraries = dependencyScope(configurations, "moduleLibraries"); + userdevCompileOnly = dependencyScope(configurations, "userdevCompileOnly"); + userdevTestFixtures = dependencyScope(configurations, "userdevTestFixtures"); + + neoFormDataOnly = resolvable(configurations, "neoFormDataOnly"); + neoFormClasspath = resolvable(configurations, "neoFormClasspath"); + modulePath = resolvable(configurations, "modulePath"); + userdevClasspath = resolvable(configurations, "userdevClasspath"); + userdevCompileOnlyClasspath = resolvable(configurations, "userdevCompileOnlyClasspath"); + userdevTestClasspath = resolvable(configurations, "userdevTestClasspath"); + launcherProfileClasspath = resolvable(configurations, "launcherProfileClasspath"); + + // Libraries & module libraries & MC dependencies need to be available when compiling in NeoDev, + // and on the runtime classpath too for IDE debugging support. + configurations.getByName("implementation").extendsFrom(libraries, moduleLibraries, neoFormDependencies); + + // runtimeClasspath is our reference for all MC dependency versions. + // Make sure that any classpath we resolve is consistent with it. + var runtimeClasspath = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME); + + neoFormDataOnly.setTransitive(false); + neoFormDataOnly.extendsFrom(neoFormData); + + neoFormClasspath.extendsFrom(neoFormDependencies); + + modulePath.extendsFrom(moduleLibraries); + modulePath.shouldResolveConsistentlyWith(runtimeClasspath); + + userdevClasspath.extendsFrom(libraries, moduleLibraries, userdevCompileOnly); + userdevClasspath.shouldResolveConsistentlyWith(runtimeClasspath); + + userdevCompileOnlyClasspath.extendsFrom(userdevCompileOnly); + userdevCompileOnlyClasspath.shouldResolveConsistentlyWith(runtimeClasspath); + + userdevTestClasspath.extendsFrom(userdevTestFixtures); + userdevTestClasspath.shouldResolveConsistentlyWith(runtimeClasspath); + + launcherProfileClasspath.extendsFrom(libraries, moduleLibraries); + launcherProfileClasspath.shouldResolveConsistentlyWith(runtimeClasspath); + + toolClasspaths = createToolClasspaths(project); + } + + private static Map createToolClasspaths(Project project) { + var configurations = project.getConfigurations(); + var dependencyFactory = project.getDependencyFactory(); + + var result = new HashMap(); + + for (var tool : Tools.values()) { + var configuration = configurations.create(tool.getGradleConfigurationName(), spec -> { + spec.setDescription("Resolves the executable for tool " + tool.name()); + spec.setCanBeConsumed(false); + // Tools are considered to be executable jars. + // Gradle requires the classpath for JavaExec to only contain a single file for these. + if (tool.isRequestFatJar()) { + spec.attributes(attr -> { + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.SHADOWED)); + }); + } + + var gav = tool.asGav(project); + spec.getDependencies().add(dependencyFactory.create(gav)); + }); + result.put(tool, configuration); + } + + return Map.copyOf(result); + } + + /** + * Gets a configuration representing the classpath for an executable tool. + * Some tools are assumed to be executable jars, and their configurations only contain a single file. + */ + public Configuration getExecutableTool(Tools tool) { + return Objects.requireNonNull(toolClasspaths.get(tool)); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtension.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtension.java new file mode 100644 index 00000000000..224c7ab7e99 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtension.java @@ -0,0 +1,35 @@ +package net.neoforged.neodev; + +import net.neoforged.moddevgradle.dsl.ModModel; +import net.neoforged.moddevgradle.dsl.RunModel; +import org.gradle.api.Action; +import org.gradle.api.NamedDomainObjectContainer; +import org.gradle.api.Project; + +public class NeoDevExtension { + public static final String NAME = "neoDev"; + + private final NamedDomainObjectContainer mods; + private final NamedDomainObjectContainer runs; + + public NeoDevExtension(Project project) { + mods = project.container(ModModel.class); + runs = project.container(RunModel.class, name -> project.getObjects().newInstance(RunModel.class, name, project, mods)); + } + + public NamedDomainObjectContainer getMods() { + return mods; + } + + public void mods(Action> action) { + action.execute(mods); + } + + public NamedDomainObjectContainer getRuns() { + return runs; + } + + public void runs(Action> action) { + action.execute(runs); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtraPlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtraPlugin.java new file mode 100644 index 00000000000..912fd4bfe50 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevExtraPlugin.java @@ -0,0 +1,79 @@ +package net.neoforged.neodev; + +import net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin; +import net.neoforged.moddevgradle.internal.NeoDevFacade; +import net.neoforged.nfrtgradle.CreateMinecraftArtifacts; +import net.neoforged.nfrtgradle.DownloadAssets; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.artifacts.dsl.DependencyFactory; +import org.gradle.api.tasks.testing.Test; + +import java.util.function.Consumer; + +// TODO: the only point of this is to configure runs that depend on neoforge. Maybe this could be done with less code duplication... +// TODO: Gradle says "thou shalt not referenceth otherth projects" yet here we are +// TODO: depend on neoforge configurations that the moddev plugin also uses +public class NeoDevExtraPlugin implements Plugin { + @Override + public void apply(Project project) { + project.getPlugins().apply(MinecraftDependenciesPlugin.class); + + var neoForgeProject = project.getRootProject().getChildProjects().get("neoforge"); + + var dependencyFactory = project.getDependencyFactory(); + var tasks = project.getTasks(); + var neoDevBuildDir = project.getLayout().getBuildDirectory().dir("neodev"); + + var extension = project.getExtensions().create(NeoDevExtension.NAME, NeoDevExtension.class); + + var modulePathDependency = projectDep(dependencyFactory, neoForgeProject, "net.neoforged:neoforge-moddev-module-path"); + + // TODO: this is temporary + var downloadAssets = neoForgeProject.getTasks().named("downloadAssets", DownloadAssets.class); + var writeNeoDevConfig = neoForgeProject.getTasks().named("writeNeoDevConfig", CreateUserDevConfig.class); + + Consumer configureLegacyClasspath = spec -> { + spec.getDependencies().add(projectDep(dependencyFactory, neoForgeProject, "net.neoforged:neoforge-dependencies")); + }; + + extension.getRuns().configureEach(run -> { + configureLegacyClasspath.accept(run.getAdditionalRuntimeClasspathConfiguration()); + }); + NeoDevFacade.setupRuns( + project, + neoDevBuildDir, + extension.getRuns(), + writeNeoDevConfig, + modulePath -> modulePath.getDependencies().add(modulePathDependency), + configureLegacyClasspath, + downloadAssets.flatMap(DownloadAssets::getAssetPropertiesFile) + ); + + var testExtension = project.getExtensions().create(NeoDevTestExtension.NAME, NeoDevTestExtension.class); + var testTask = tasks.register("junitTest", Test.class, test -> test.setGroup("verification")); + tasks.named("check").configure(task -> task.dependsOn(testTask)); + + NeoDevFacade.setupTestTask( + project, + neoDevBuildDir, + testTask, + writeNeoDevConfig, + testExtension.getLoadedMods(), + testExtension.getTestedMod(), + modulePath -> modulePath.getDependencies().add(modulePathDependency), + configureLegacyClasspath, + downloadAssets.flatMap(DownloadAssets::getAssetPropertiesFile) + ); + } + + private static ProjectDependency projectDep(DependencyFactory dependencyFactory, Project project, String capabilityNotation) { + var dep = dependencyFactory.create(project); + dep.capabilities(caps -> { + caps.requireCapability(capabilityNotation); + }); + return dep; + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java new file mode 100644 index 00000000000..e7f9f779342 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java @@ -0,0 +1,540 @@ +package net.neoforged.neodev; + +import net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin; +import net.neoforged.moddevgradle.internal.NeoDevFacade; +import net.neoforged.moddevgradle.tasks.JarJar; +import net.neoforged.neodev.installer.CreateArgsFile; +import net.neoforged.neodev.installer.CreateInstallerProfile; +import net.neoforged.neodev.installer.CreateLauncherProfile; +import net.neoforged.neodev.installer.InstallerProcessor; +import net.neoforged.neodev.utils.DependencyUtils; +import net.neoforged.nfrtgradle.CreateMinecraftArtifacts; +import net.neoforged.nfrtgradle.DownloadAssets; +import net.neoforged.nfrtgradle.NeoFormRuntimePlugin; +import net.neoforged.nfrtgradle.NeoFormRuntimeTask; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; +import org.gradle.api.file.Directory; +import org.gradle.api.file.RegularFile; +import org.gradle.api.plugins.BasePluginExtension; +import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Sync; +import org.gradle.api.tasks.TaskProvider; +import org.gradle.api.tasks.bundling.AbstractArchiveTask; +import org.gradle.api.tasks.bundling.Jar; +import org.gradle.api.tasks.bundling.Zip; + +import java.io.File; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class NeoDevPlugin implements Plugin { + static final String GROUP = "neoforge development"; + static final String INTERNAL_GROUP = "neoforge development/internal"; + + @Override + public void apply(Project project) { + project.getPlugins().apply(MinecraftDependenciesPlugin.class); + + var dependencyFactory = project.getDependencyFactory(); + var tasks = project.getTasks(); + var neoDevBuildDir = project.getLayout().getBuildDirectory().dir("neodev"); + + var rawNeoFormVersion = project.getProviders().gradleProperty("neoform_version"); + var fmlVersion = project.getProviders().gradleProperty("fancy_mod_loader_version"); + var minecraftVersion = project.getProviders().gradleProperty("minecraft_version"); + var neoForgeVersion = project.provider(() -> project.getVersion().toString()); + var mcAndNeoFormVersion = minecraftVersion.zip(rawNeoFormVersion, (mc, nf) -> mc + "-" + nf); + + var extension = project.getExtensions().create(NeoDevExtension.NAME, NeoDevExtension.class); + var configurations = NeoDevConfigurations.createAndSetup(project); + + /* + * MINECRAFT SOURCES SETUP + */ + // 1. Obtain decompiled Minecraft sources jar using NeoForm. + var createSourceArtifacts = configureMinecraftDecompilation(project); + // Task must run on sync to have MC resources available for IDEA nondelegated builds. + NeoDevFacade.runTaskOnProjectSync(project, createSourceArtifacts); + + // 2. Apply AT to the source jar from 1. + var atFile = project.getRootProject().file("src/main/resources/META-INF/accesstransformer.cfg"); + var applyAt = configureAccessTransformer( + project, + configurations, + createSourceArtifacts, + neoDevBuildDir, + atFile); + + // 3. Apply patches to the source jar from 2. + var patchesFolder = project.getRootProject().file("patches"); + var applyPatches = tasks.register("applyPatches", ApplyPatches.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getOriginalJar().set(applyAt.flatMap(ApplyAccessTransformer::getOutputJar)); + task.getPatchesFolder().set(patchesFolder); + task.getPatchedJar().set(neoDevBuildDir.map(dir -> dir.file("artifacts/patched-sources.jar"))); + task.getRejectsFolder().set(project.getRootProject().file("rejects")); + }); + + // 4. Unpack jar from 3. + var mcSourcesPath = project.file("src/main/java"); + tasks.register("setup", Sync.class, task -> { + task.setGroup(GROUP); + task.from(project.zipTree(applyPatches.flatMap(ApplyPatches::getPatchedJar))); + task.into(mcSourcesPath); + }); + + /* + * RUNS SETUP + */ + + // 1. Write configs that contain the runs in a format understood by MDG/NG/etc. Currently one for neodev and one for userdev. + var writeNeoDevConfig = tasks.register("writeNeoDevConfig", CreateUserDevConfig.class, task -> { + task.getForNeoDev().set(true); + task.getUserDevConfig().set(neoDevBuildDir.map(dir -> dir.file("neodev-config.json"))); + }); + var writeUserDevConfig = tasks.register("writeUserDevConfig", CreateUserDevConfig.class, task -> { + task.getForNeoDev().set(false); + task.getUserDevConfig().set(neoDevBuildDir.map(dir -> dir.file("userdev-config.json"))); + }); + for (var taskProvider : List.of(writeNeoDevConfig, writeUserDevConfig)) { + taskProvider.configure(task -> { + task.setGroup(INTERNAL_GROUP); + task.getFmlVersion().set(fmlVersion); + task.getMinecraftVersion().set(minecraftVersion); + task.getNeoForgeVersion().set(neoForgeVersion); + task.getRawNeoFormVersion().set(rawNeoFormVersion); + task.getLibraries().addAll(DependencyUtils.configurationToGavList(configurations.userdevClasspath)); + task.getModules().addAll(DependencyUtils.configurationToGavList(configurations.modulePath)); + task.getTestLibraries().addAll(DependencyUtils.configurationToGavList(configurations.userdevTestClasspath)); + task.getTestLibraries().add(neoForgeVersion.map(v -> "net.neoforged:testframework:" + v)); + task.getIgnoreList().addAll(configurations.userdevCompileOnlyClasspath.getIncoming().getArtifacts().getResolvedArtifacts().map(results -> { + return results.stream().map(r -> r.getFile().getName()).toList(); + })); + task.getIgnoreList().addAll("client-extra", "neoforge-"); + task.getBinpatcherGav().set(Tools.BINPATCHER.asGav(project)); + }); + } + + // 2. Task to download assets. + var downloadAssets = tasks.register("downloadAssets", DownloadAssets.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getNeoFormArtifact().set(mcAndNeoFormVersion.map(v -> "net.neoforged:neoform:" + v + "@zip")); + task.getAssetPropertiesFile().set(neoDevBuildDir.map(dir -> dir.file("minecraft_assets.properties"))); + }); + + // FML needs Minecraft resources on the classpath to find it. Add to runtimeOnly so subprojects also get it at runtime. + var runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME); + runtimeClasspath.getDependencies().add( + dependencyFactory.create( + project.files(createSourceArtifacts.flatMap(CreateMinecraftArtifacts::getResourcesArtifact)) + ) + ); + // 3. Let MDG do the rest of the setup. :) + NeoDevFacade.setupRuns( + project, + neoDevBuildDir, + extension.getRuns(), + writeNeoDevConfig, + modulePath -> { + modulePath.extendsFrom(configurations.moduleLibraries); + }, + legacyClassPath -> { + legacyClassPath.getDependencies().addLater(mcAndNeoFormVersion.map(v -> dependencyFactory.create("net.neoforged:neoform:" + v).capabilities(caps -> { + caps.requireCapability("net.neoforged:neoform-dependencies"); + }))); + legacyClassPath.extendsFrom(configurations.libraries, configurations.moduleLibraries, configurations.userdevCompileOnly); + }, + downloadAssets.flatMap(DownloadAssets::getAssetPropertiesFile) + ); + // TODO: Gradle run tasks should be moved to gradle group GROUP + + /* + * OTHER TASKS + */ + + // Generate source patches into a patch archive. + var genSourcePatches = tasks.register("generateSourcePatches", GenerateSourcePatches.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getOriginalJar().set(applyAt.flatMap(ApplyAccessTransformer::getOutputJar)); + task.getModifiedSources().set(project.file("src/main/java")); + task.getPatchesJar().set(neoDevBuildDir.map(dir -> dir.file("source-patches.zip"))); + }); + + // Update the patch/ folder with the current patches. + tasks.register("genPatches", Sync.class, task -> { + task.setGroup(GROUP); + task.from(project.zipTree(genSourcePatches.flatMap(GenerateSourcePatches::getPatchesJar))); + task.into(project.getRootProject().file("patches")); + }); + + // Universal jar = the jar that contains NeoForge classes + // TODO: signing? + var universalJar = tasks.register("universalJar", Jar.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getArchiveClassifier().set("universal"); + + task.from(project.zipTree( + tasks.named("jar", Jar.class).flatMap(AbstractArchiveTask::getArchiveFile))); + task.exclude("net/minecraft/**"); + task.exclude("com/**"); + task.exclude("mcp/**"); + + task.manifest(manifest -> { + manifest.attributes(Map.of("FML-System-Mods", "neoforge")); + // These attributes are used from NeoForgeVersion.java to find the NF version without command line arguments. + manifest.attributes( + Map.of( + "Specification-Title", "NeoForge", + "Specification-Vendor", "NeoForge", + "Specification-Version", project.getVersion().toString().substring(0, project.getVersion().toString().lastIndexOf(".")), + "Implementation-Title", project.getGroup(), + "Implementation-Version", project.getVersion(), + "Implementation-Vendor", "NeoForged"), + "net/neoforged/neoforge/internal/versions/neoforge/"); + manifest.attributes( + Map.of( + "Specification-Title", "Minecraft", + "Specification-Vendor", "Mojang", + "Specification-Version", minecraftVersion, + "Implementation-Title", "MCP", + "Implementation-Version", mcAndNeoFormVersion, + "Implementation-Vendor", "NeoForged"), + "net/neoforged/neoforge/versions/neoform/"); + }); + }); + + var jarJarTask = JarJar.registerWithConfiguration(project, "jarJar"); + jarJarTask.configure(task -> task.setGroup(INTERNAL_GROUP)); + universalJar.configure(task -> task.from(jarJarTask)); + + var createCleanArtifacts = tasks.register("createCleanArtifacts", CreateCleanArtifacts.class, task -> { + task.setGroup(INTERNAL_GROUP); + var cleanArtifactsDir = neoDevBuildDir.map(dir -> dir.dir("artifacts/clean")); + task.getCleanClientJar().set(cleanArtifactsDir.map(dir -> dir.file("client.jar"))); + task.getRawServerJar().set(cleanArtifactsDir.map(dir -> dir.file("raw-server.jar"))); + task.getCleanServerJar().set(cleanArtifactsDir.map(dir -> dir.file("server.jar"))); + task.getCleanJoinedJar().set(cleanArtifactsDir.map(dir -> dir.file("joined.jar"))); + task.getMergedMappings().set(cleanArtifactsDir.map(dir -> dir.file("merged-mappings.txt"))); + task.getNeoFormArtifact().set(mcAndNeoFormVersion.map(version -> "net.neoforged:neoform:" + version + "@zip")); + }); + + var binaryPatchOutputs = configureBinaryPatchCreation( + project, + configurations, + createCleanArtifacts, + neoDevBuildDir, + patchesFolder + ); + + // Launcher profile = the version.json file used by the Minecraft launcher. + var createLauncherProfile = tasks.register("createLauncherProfile", CreateLauncherProfile.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getFmlVersion().set(fmlVersion); + task.getMinecraftVersion().set(minecraftVersion); + task.getNeoForgeVersion().set(neoForgeVersion); + task.getRawNeoFormVersion().set(rawNeoFormVersion); + task.setLibraries(configurations.launcherProfileClasspath); + task.getRepositoryURLs().set(project.provider(() -> { + List repos = new ArrayList<>(); + for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) { + var uri = repo.getUrl(); + if (!uri.toString().endsWith("/")) { + uri = URI.create(uri + "/"); + } + repos.add(uri); + } + return repos; + })); + task.getIgnoreList().addAll("client-extra", "neoforge-"); + task.setModules(configurations.modulePath); + task.getLauncherProfile().set(neoDevBuildDir.map(dir -> dir.file("launcher-profile.json"))); + }); + + // Installer profile = the .json file used by the NeoForge installer. + var createInstallerProfile = tasks.register("createInstallerProfile", CreateInstallerProfile.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getMinecraftVersion().set(minecraftVersion); + task.getNeoForgeVersion().set(neoForgeVersion); + task.getMcAndNeoFormVersion().set(mcAndNeoFormVersion); + task.getIcon().set(project.getRootProject().file("docs/assets/neoforged.ico")); + // Anything that is on the launcher classpath should be downloaded by the installer. + // (At least on the server side). + task.addLibraries(configurations.launcherProfileClasspath); + // We need the NeoForm zip for the SRG mappings. + task.addLibraries(configurations.neoFormDataOnly); + task.getRepositoryURLs().set(project.provider(() -> { + List repos = new ArrayList<>(); + for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) { + var uri = repo.getUrl(); + if (!uri.toString().endsWith("/")) { + uri = URI.create(uri + "/"); + } + repos.add(uri); + } + return repos; + })); + task.getUniversalJar().set(universalJar.flatMap(AbstractArchiveTask::getArchiveFile)); + task.getInstallerProfile().set(neoDevBuildDir.map(dir -> dir.file("installer-profile.json"))); + + // Make all installer processor tools available to the profile + for (var installerProcessor : InstallerProcessor.values()) { + var configuration = configurations.getExecutableTool(installerProcessor.tool); + // Different processors might use different versions of the same library, + // but that is fine because each processor gets its own classpath. + task.addLibraries(configuration); + task.getProcessorClasspaths().put(installerProcessor, DependencyUtils.configurationToGavList(configuration)); + task.getProcessorGavs().put(installerProcessor, installerProcessor.tool.asGav(project)); + } + }); + + var createWindowsServerArgsFile = tasks.register("createWindowsServerArgsFile", CreateArgsFile.class, task -> { + task.setLibraries(";", configurations.launcherProfileClasspath, configurations.modulePath); + task.getArgsFile().set(neoDevBuildDir.map(dir -> dir.file("windows-server-args.txt"))); + }); + var createUnixServerArgsFile = tasks.register("createUnixServerArgsFile", CreateArgsFile.class, task -> { + task.setLibraries(":", configurations.launcherProfileClasspath, configurations.modulePath); + task.getArgsFile().set(neoDevBuildDir.map(dir -> dir.file("unix-server-args.txt"))); + }); + + for (var taskProvider : List.of(createWindowsServerArgsFile, createUnixServerArgsFile)) { + taskProvider.configure(task -> { + task.setGroup(INTERNAL_GROUP); + task.getTemplate().set(project.getRootProject().file("server_files/args.txt")); + task.getFmlVersion().set(fmlVersion); + task.getMinecraftVersion().set(minecraftVersion); + task.getNeoForgeVersion().set(neoForgeVersion); + task.getRawNeoFormVersion().set(rawNeoFormVersion); + // In theory, new BootstrapLauncher shouldn't need the module path in the ignore list anymore. + // However, in server installs libraries are passed as relative paths here. + // Module path detection doesn't currently work with relative paths (BootstrapLauncher #20). + task.getIgnoreList().set(configurations.modulePath.getIncoming().getArtifacts().getResolvedArtifacts().map(results -> { + return results.stream().map(r -> r.getFile().getName()).toList(); + })); + task.getRawServerJar().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getRawServerJar)); + }); + } + + var installerConfig = configurations.getExecutableTool(Tools.LEGACYINSTALLER); + // TODO: signing? + // We want to inherit the executable JAR manifest from LegacyInstaller. + // - Jar tasks have special manifest handling, so use Zip. + // - The manifest must be the first entry in the jar so LegacyInstaller has to be the first input. + var installerJar = tasks.register("installerJar", Zip.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getArchiveClassifier().set("installer"); + task.getArchiveExtension().set("jar"); + task.setMetadataCharset("UTF-8"); + task.getDestinationDirectory().convention(project.getExtensions().getByType(BasePluginExtension.class).getLibsDirectory()); + + task.from(project.zipTree(project.provider(installerConfig::getSingleFile)), spec -> { + spec.exclude("big_logo.png"); + }); + task.from(createLauncherProfile.flatMap(CreateLauncherProfile::getLauncherProfile), spec -> { + spec.rename(s -> "version.json"); + }); + task.from(createInstallerProfile.flatMap(CreateInstallerProfile::getInstallerProfile), spec -> { + spec.rename(s -> "install_profile.json"); + }); + task.from(project.getRootProject().file("src/main/resources/url.png")); + task.from(project.getRootProject().file("src/main/resources/neoforged_logo.png"), spec -> { + spec.rename(s -> "big_logo.png"); + }); + task.from(createUnixServerArgsFile.flatMap(CreateArgsFile::getArgsFile), spec -> { + spec.into("data"); + spec.rename(s -> "unix_args.txt"); + }); + task.from(createWindowsServerArgsFile.flatMap(CreateArgsFile::getArgsFile), spec -> { + spec.into("data"); + spec.rename(s -> "win_args.txt"); + }); + task.from(binaryPatchOutputs.binaryPatchesForClient(), spec -> { + spec.into("data"); + spec.rename(s -> "client.lzma"); + }); + task.from(binaryPatchOutputs.binaryPatchesForServer(), spec -> { + spec.into("data"); + spec.rename(s -> "server.lzma"); + }); + var mavenPath = neoForgeVersion.map(v -> "net/neoforged/neoforge/" + v); + task.getInputs().property("mavenPath", mavenPath); + task.from(project.getRootProject().files("server_files"), spec -> { + spec.into("data"); + spec.exclude("args.txt"); + spec.filter(s -> { + return s.replaceAll("@MAVEN_PATH@", mavenPath.get()); + }); + }); + + // This is true by default (see gradle.properties), and needs to be disabled explicitly when building (see release.yml). + String installerDebugProperty = "neogradle.runtime.platform.installer.debug"; + if (project.getProperties().containsKey(installerDebugProperty) && Boolean.parseBoolean(project.getProperties().get(installerDebugProperty).toString())) { + task.from(universalJar.flatMap(AbstractArchiveTask::getArchiveFile), spec -> { + spec.into(String.format("/maven/net/neoforged/neoforge/%s/", neoForgeVersion.get())); + spec.rename(name -> String.format("neoforge-%s-universal.jar", neoForgeVersion.get())); + }); + } + }); + + var userdevJar = tasks.register("userdevJar", Jar.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.getArchiveClassifier().set("userdev"); + + task.from(writeUserDevConfig.flatMap(CreateUserDevConfig::getUserDevConfig), spec -> { + spec.rename(s -> "config.json"); + }); + task.from(atFile, spec -> { + spec.into("ats/"); + }); + task.from(binaryPatchOutputs.binaryPatchesForMerged(), spec -> { + spec.rename(s -> "joined.lzma"); + }); + task.from(project.zipTree(genSourcePatches.flatMap(GenerateSourcePatches::getPatchesJar)), spec -> { + spec.into("patches/"); + }); + }); + + project.getExtensions().getByType(JavaPluginExtension.class).withSourcesJar(); + var sourcesJarProvider = project.getTasks().named("sourcesJar", Jar.class); + sourcesJarProvider.configure(task -> { + task.exclude("net/minecraft/**"); + task.exclude("com/**"); + task.exclude("mcp/**"); + }); + + tasks.named("assemble", task -> { + task.dependsOn(installerJar); + task.dependsOn(universalJar); + task.dependsOn(userdevJar); + task.dependsOn(sourcesJarProvider); + }); + } + + private static TaskProvider configureAccessTransformer( + Project project, + NeoDevConfigurations configurations, + TaskProvider createSourceArtifacts, + Provider neoDevBuildDir, + File atFile) { + + // Pass -PvalidateAccessTransformers to validate ATs. + var validateAts = project.getProviders().gradleProperty("validateAccessTransformers").map(p -> true).orElse(false); + return project.getTasks().register("applyAccessTransformer", ApplyAccessTransformer.class, task -> { + task.setGroup(INTERNAL_GROUP); + task.classpath(configurations.getExecutableTool(Tools.JST)); + task.getInputJar().set(createSourceArtifacts.flatMap(CreateMinecraftArtifacts::getSourcesArtifact)); + task.getAccessTransformer().set(atFile); + task.getValidate().set(validateAts); + task.getOutputJar().set(neoDevBuildDir.map(dir -> dir.file("artifacts/access-transformed-sources.jar"))); + task.getLibraries().from(configurations.neoFormClasspath); + task.getLibrariesFile().set(neoDevBuildDir.map(dir -> dir.file("minecraft-libraries-for-jst.txt"))); + }); + } + + private static BinaryPatchOutputs configureBinaryPatchCreation(Project project, + NeoDevConfigurations configurations, + TaskProvider createCleanArtifacts, + Provider neoDevBuildDir, + File sourcesPatchesFolder) { + var tasks = project.getTasks(); + + var artConfig = configurations.getExecutableTool(Tools.AUTO_RENAMING_TOOL); + var remapClientJar = tasks.register("remapClientJar", RemapJar.class, task -> { + task.setDescription("Creates a Minecraft client jar with the official mappings applied. Used as the base for generating binary patches for the client."); + task.getInputJar().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getCleanClientJar)); + task.getOutputJar().set(neoDevBuildDir.map(dir -> dir.file("remapped-client.jar"))); + }); + var remapServerJar = tasks.register("remapServerJar", RemapJar.class, task -> { + task.setDescription("Creates a Minecraft dedicated server jar with the official mappings applied. Used as the base for generating binary patches for the client."); + task.getInputJar().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getCleanServerJar)); + task.getOutputJar().set(neoDevBuildDir.map(dir -> dir.file("remapped-server.jar"))); + }); + for (var remapTask : List.of(remapClientJar, remapServerJar)) { + remapTask.configure(task -> { + task.setGroup(INTERNAL_GROUP); + task.classpath(artConfig); + task.getMappings().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getMergedMappings)); + }); + } + + var binpatcherConfig = configurations.getExecutableTool(Tools.BINPATCHER); + var generateMergedBinPatches = tasks.register("generateMergedBinPatches", GenerateBinaryPatches.class, task -> { + task.setDescription("Creates binary patch files by diffing a merged client/server jar-file and the compiled Minecraft classes in this project."); + task.getCleanJar().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getCleanJoinedJar)); + task.getOutputFile().set(neoDevBuildDir.map(dir -> dir.file("merged-binpatches.lzma"))); + }); + var generateClientBinPatches = tasks.register("generateClientBinPatches", GenerateBinaryPatches.class, task -> { + task.setDescription("Creates binary patch files by diffing a merged client jar-file and the compiled Minecraft classes in this project."); + task.getCleanJar().set(remapClientJar.flatMap(RemapJar::getOutputJar)); + task.getOutputFile().set(neoDevBuildDir.map(dir -> dir.file("client-binpatches.lzma"))); + }); + var generateServerBinPatches = tasks.register("generateServerBinPatches", GenerateBinaryPatches.class, task -> { + task.setDescription("Creates binary patch files by diffing a merged server jar-file and the compiled Minecraft classes in this project."); + task.getCleanJar().set(remapServerJar.flatMap(RemapJar::getOutputJar)); + task.getOutputFile().set(neoDevBuildDir.map(dir -> dir.file("server-binpatches.lzma"))); + }); + for (var generateBinPatchesTask : List.of(generateMergedBinPatches, generateClientBinPatches, generateServerBinPatches)) { + generateBinPatchesTask.configure(task -> { + task.setGroup(INTERNAL_GROUP); + task.classpath(binpatcherConfig); + task.getPatchedJar().set(tasks.named("jar", Jar.class).flatMap(Jar::getArchiveFile)); + task.getSourcePatchesFolder().set(sourcesPatchesFolder); + task.getMappings().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getMergedMappings)); + }); + } + + return new BinaryPatchOutputs( + generateMergedBinPatches.flatMap(GenerateBinaryPatches::getOutputFile), + generateClientBinPatches.flatMap(GenerateBinaryPatches::getOutputFile), + generateServerBinPatches.flatMap(GenerateBinaryPatches::getOutputFile) + ); + } + + private record BinaryPatchOutputs( + Provider binaryPatchesForMerged, + Provider binaryPatchesForClient, + Provider binaryPatchesForServer + ) { + } + + /** + * Sets up NFRT, and creates the sources and resources artifacts. + */ + static TaskProvider configureMinecraftDecompilation(Project project) { + project.getPlugins().apply(NeoFormRuntimePlugin.class); + + var configurations = project.getConfigurations(); + var dependencyFactory = project.getDependencyFactory(); + var tasks = project.getTasks(); + var neoDevBuildDir = project.getLayout().getBuildDirectory().dir("neodev"); + + var rawNeoFormVersion = project.getProviders().gradleProperty("neoform_version"); + var minecraftVersion = project.getProviders().gradleProperty("minecraft_version"); + var mcAndNeoFormVersion = minecraftVersion.zip(rawNeoFormVersion, (mc, nf) -> mc + "-" + nf); + + // Configuration for all artifacts that should be passed to NFRT to prevent repeated downloads + var neoFormRuntimeArtifactManifestNeoForm = configurations.create("neoFormRuntimeArtifactManifestNeoForm", spec -> { + spec.setCanBeConsumed(false); + spec.setCanBeResolved(true); + spec.getDependencies().addLater(mcAndNeoFormVersion.map(version -> { + return dependencyFactory.create("net.neoforged:neoform:" + version); + })); + }); + + tasks.withType(NeoFormRuntimeTask.class, task -> { + task.addArtifactsToManifest(neoFormRuntimeArtifactManifestNeoForm); + }); + + return tasks.register("createSourceArtifacts", CreateMinecraftArtifacts.class, task -> { + var minecraftArtifactsDir = neoDevBuildDir.map(dir -> dir.dir("artifacts")); + task.getSourcesArtifact().set(minecraftArtifactsDir.map(dir -> dir.file("base-sources.jar"))); + task.getResourcesArtifact().set(minecraftArtifactsDir.map(dir -> dir.file("minecraft-resources.jar"))); + task.getNeoFormArtifact().set(mcAndNeoFormVersion.map(version -> "net.neoforged:neoform:" + version + "@zip")); + }); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevTestExtension.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevTestExtension.java new file mode 100644 index 00000000000..57d3f7be339 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevTestExtension.java @@ -0,0 +1,30 @@ +package net.neoforged.neodev; + +import net.neoforged.moddevgradle.dsl.ModModel; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.SetProperty; + +import javax.inject.Inject; + +public abstract class NeoDevTestExtension { + public static final String NAME = "neoDevTest"; + + @Inject + public NeoDevTestExtension() { + } + + /** + * The mod that will be loaded in JUnit tests. + * The compiled classes from {@code src/test/java} and the resources from {@code src/test/resources} + * will be added to that mod at runtime. + */ + public abstract Property getTestedMod(); + + /** + * The mods to load when running unit tests. Defaults to all mods registered in the project. + * This must contain {@link #getTestedMod()}. + * + * @see ModModel + */ + public abstract SetProperty getLoadedMods(); +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/RemapJar.java b/buildSrc/src/main/java/net/neoforged/neodev/RemapJar.java new file mode 100644 index 00000000000..e93ccb8b940 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/RemapJar.java @@ -0,0 +1,53 @@ +package net.neoforged.neodev; + +import org.gradle.api.GradleException; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.JavaExec; +import org.gradle.api.tasks.OutputFile; + +import javax.inject.Inject; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * Produces a remapped jar-file that has almost no other changes applied with the intent of being + * the base against which we {@link GenerateBinaryPatches generate binary patches}. + *

+ * The installer produces the same Jar file as this task does and then applies the patches against that. + *

+ * Any changes to the options used here have to be reflected in the {@link net.neoforged.neodev.installer.CreateInstallerProfile installer profile} + * and vice versa, to ensure the patches are generated against the same binary files as they are applied to later. + */ +abstract class RemapJar extends JavaExec { + @Inject + public RemapJar() {} + + @InputFile + abstract RegularFileProperty getInputJar(); + + @InputFile + abstract RegularFileProperty getMappings(); + + @OutputFile + abstract RegularFileProperty getOutputJar(); + + @Override + public void exec() { + args("--input", getInputJar().get().getAsFile().getAbsolutePath()); + args("--output", getOutputJar().get().getAsFile().getAbsolutePath()); + args("--names", getMappings().get().getAsFile().getAbsolutePath()); + args("--ann-fix", "--ids-fix", "--src-fix", "--record-fix"); + + var logFile = new File(getTemporaryDir(), "console.log"); + try (var out = new BufferedOutputStream(new FileOutputStream(logFile))) { + getLogger().info("Logging ART console output to {}", logFile.getAbsolutePath()); + setStandardOutput(out); + super.exec(); + } catch (IOException e) { + throw new GradleException("Failed to remap jar.", e); + } + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/Tools.java b/buildSrc/src/main/java/net/neoforged/neodev/Tools.java new file mode 100644 index 00000000000..a9f91066975 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/Tools.java @@ -0,0 +1,53 @@ +package net.neoforged.neodev; + +import org.gradle.api.Project; + +// If a GAV is changed, make sure to change the corresponding renovate comment in gradle.properties. +public enum Tools { + // Fatjar jst-cli-bundle instead of jst-cli because publication of the latter is currently broken. + JST("net.neoforged.jst:jst-cli-bundle:%s", "jst_version", "toolJstClasspath", true), + // Fatjar because the contents are copy/pasted into the installer jar which must be standalone. + LEGACYINSTALLER("net.neoforged:legacyinstaller:%s:shrunk", "legacyinstaller_version", "toolLegacyinstallerClasspath", true), + // Fatjar because the slim jar currently does not have the main class set in its manifest. + AUTO_RENAMING_TOOL("net.neoforged:AutoRenamingTool:%s:all", "art_version", "toolAutoRenamingToolClasspath", true), + INSTALLERTOOLS("net.neoforged.installertools:installertools:%s", "installertools_version", "toolInstallertoolsClasspath", false), + JARSPLITTER("net.neoforged.installertools:jarsplitter:%s", "installertools_version", "toolJarsplitterClasspath", false), + // Fatjar because it was like that in the userdev json in the past. + // To reconsider, we need to get in touch with 3rd party plugin developers or wait for a BC window. + BINPATCHER("net.neoforged.installertools:binarypatcher:%s:fatjar", "installertools_version", "toolBinpatcherClasspath", true); + + private final String gavPattern; + private final String versionProperty; + private final String gradleConfigurationName; + private final boolean requestFatJar; + + Tools(String gavPattern, String versionProperty, String gradleConfigurationName, boolean requestFatJar) { + this.gavPattern = gavPattern; + this.versionProperty = versionProperty; + this.gradleConfigurationName = gradleConfigurationName; + this.requestFatJar = requestFatJar; + } + + /** + * The name of the Gradle {@link org.gradle.api.artifacts.Configuration} used to resolve this particular tool. + */ + public String getGradleConfigurationName() { + return gradleConfigurationName; + } + + /** + * Some tools may be incorrectly packaged and declare transitive dependencies even for their "fatjar" variants. + * Gradle will not run these, so we ignore them. + */ + public boolean isRequestFatJar() { + return requestFatJar; + } + + public String asGav(Project project) { + var version = project.property(versionProperty); + if (version == null) { + throw new IllegalStateException("Could not find property " + versionProperty); + } + return gavPattern.formatted(version); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java new file mode 100644 index 00000000000..6b403d5b944 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java @@ -0,0 +1,126 @@ +package net.neoforged.neodev.installer; + +import net.neoforged.neodev.utils.DependencyUtils; +import org.gradle.api.DefaultTask; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.ArchiveOperations; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +import javax.inject.Inject; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Creates the JVM/program argument files used by the dedicated server launcher. + */ +public abstract class CreateArgsFile extends DefaultTask { + @Inject + public CreateArgsFile() {} + + @InputFile + public abstract RegularFileProperty getTemplate(); + + @Input + public abstract Property getFmlVersion(); + + @Input + public abstract Property getMinecraftVersion(); + + @Input + public abstract Property getNeoForgeVersion(); + + @Input + public abstract Property getRawNeoFormVersion(); + + @Input + protected abstract Property getPathSeparator(); + + @Input + protected abstract Property getModules(); + + @Input + public abstract ListProperty getIgnoreList(); + + @Input + protected abstract Property getClasspath(); + + public void setLibraries(String separator, Configuration classpath, Configuration modulePath) { + getPathSeparator().set(separator); + getClasspath().set(DependencyUtils.configurationToClasspath(classpath, "libraries/", separator)); + getModules().set(DependencyUtils.configurationToClasspath(modulePath, "libraries/", separator)); + } + + @InputFile + public abstract RegularFileProperty getRawServerJar(); + + @OutputFile + public abstract RegularFileProperty getArgsFile(); + + @Inject + protected abstract ArchiveOperations getArchiveOperations(); + + private String resolveClasspath() throws IOException { + var ourClasspath = getClasspath().get() + getPathSeparator().get() + + "libraries/net/minecraft/server/%s/server-%s-extra.jar".formatted( + getRawNeoFormVersion().get(), getRawNeoFormVersion().get()); + + // The raw server jar also contains its own classpath. + // We want to make sure that our versions of the libraries are used when there is a conflict. + var ourClasspathEntries = Stream.of(ourClasspath.split(getPathSeparator().get())) + .map(CreateArgsFile::stripVersionSuffix) + .collect(Collectors.toSet()); + + var serverClasspath = getArchiveOperations().zipTree(getRawServerJar()) + .filter(spec -> spec.getPath().endsWith("META-INF" + File.separator + "classpath-joined")) + .getSingleFile(); + + var filteredServerClasspath = Stream.of(Files.readString(serverClasspath.toPath()).split(";")) + .filter(path -> !ourClasspathEntries.contains(stripVersionSuffix(path))) + // Exclude the actual MC server jar, which is under versions/ + .filter(path -> path.startsWith("libraries/")) + .collect(Collectors.joining(getPathSeparator().get())); + + return ourClasspath + getPathSeparator().get() + filteredServerClasspath; + } + + // Example: + // Convert "libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar" + // to "libraries/com/github/oshi/oshi-core". + private static String stripVersionSuffix(String classpathEntry) { + var parts = classpathEntry.split("/"); + return String.join("/", List.of(parts).subList(0, parts.length - 2)); + } + + @TaskAction + public void createArgsFile() throws IOException { + var replacements = new HashMap(); + replacements.put("@MODULE_PATH@", getModules().get()); + replacements.put("@MODULES@", "ALL-MODULE-PATH"); + replacements.put("@IGNORE_LIST@", String.join(",", getIgnoreList().get())); + replacements.put("@PLUGIN_LAYER_LIBRARIES@", ""); + replacements.put("@GAME_LAYER_LIBRARIES@", ""); + replacements.put("@CLASS_PATH@", resolveClasspath()); + replacements.put("@TASK@", "forgeserver"); + replacements.put("@FORGE_VERSION@", getNeoForgeVersion().get()); + replacements.put("@FML_VERSION@", getFmlVersion().get()); + replacements.put("@MC_VERSION@", getMinecraftVersion().get()); + replacements.put("@MCP_VERSION@", getRawNeoFormVersion().get()); + + var contents = Files.readString(getTemplate().get().getAsFile().toPath()); + for (var entry : replacements.entrySet()) { + contents = contents.replaceAll(entry.getKey(), entry.getValue()); + } + Files.writeString(getArgsFile().get().getAsFile().toPath(), contents); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java new file mode 100644 index 00000000000..3b745f744aa --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java @@ -0,0 +1,230 @@ +package net.neoforged.neodev.installer; + +import com.google.gson.GsonBuilder; +import net.neoforged.neodev.utils.FileUtils; +import net.neoforged.neodev.utils.MavenIdentifier; +import org.gradle.api.DefaultTask; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.MapProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.Nested; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; +import org.jetbrains.annotations.Nullable; + +import javax.inject.Inject; +import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Base64; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * Creates the JSON profile used by legacyinstaller for installing the client into the vanilla launcher, + * or installing a dedicated server. + */ +public abstract class CreateInstallerProfile extends DefaultTask { + @Inject + public CreateInstallerProfile() {} + + @Input + public abstract Property getMinecraftVersion(); + + @Input + public abstract Property getNeoForgeVersion(); + + @Input + public abstract Property getMcAndNeoFormVersion(); + + @InputFile + public abstract RegularFileProperty getIcon(); + + @Nested + protected abstract ListProperty getLibraryFiles(); + + public void addLibraries(Configuration libraries) { + getLibraryFiles().addAll(IdentifiedFile.listFromConfiguration(getProject(), libraries)); + } + + @Input + public abstract ListProperty getRepositoryURLs(); + + @Input + public abstract MapProperty> getProcessorClasspaths(); + + @Input + public abstract MapProperty getProcessorGavs(); + + @InputFile + public abstract RegularFileProperty getUniversalJar(); + + @OutputFile + public abstract RegularFileProperty getInstallerProfile(); + + private void addProcessor(List processors, @Nullable List sides, InstallerProcessor processor, List args) { + var classpath = getProcessorClasspaths().get().get(processor); + var mainJar = getProcessorGavs().get().get(processor); + if (!classpath.contains(mainJar)) { + throw new IllegalStateException("Processor %s is not included in its own classpath %s".formatted(mainJar, classpath)); + } + processors.add(new ProcessorEntry(sides, mainJar, classpath, args)); + } + + @TaskAction + public void createInstallerProfile() throws IOException { + var icon = "data:image/png;base64," + Base64.getEncoder().encodeToString(Files.readAllBytes(getIcon().getAsFile().get().toPath())); + + var data = new LinkedHashMap(); + var neoFormVersion = getMcAndNeoFormVersion().get(); + data.put("MAPPINGS", new LauncherDataEntry(String.format("[net.neoforged:neoform:%s:mappings@txt]", neoFormVersion), String.format("[net.neoforged:neoform:%s:mappings@txt]", neoFormVersion))); + data.put("MOJMAPS", new LauncherDataEntry(String.format("[net.minecraft:client:%s:mappings@txt]", neoFormVersion), String.format("[net.minecraft:server:%s:mappings@txt]", neoFormVersion))); + data.put("MERGED_MAPPINGS", new LauncherDataEntry(String.format("[net.neoforged:neoform:%s:mappings-merged@txt]", neoFormVersion), String.format("[net.neoforged:neoform:%s:mappings-merged@txt]", neoFormVersion))); + data.put("BINPATCH", new LauncherDataEntry("/data/client.lzma", "/data/server.lzma")); + data.put("MC_UNPACKED", new LauncherDataEntry(String.format("[net.minecraft:client:%s:unpacked]", neoFormVersion), String.format("[net.minecraft:server:%s:unpacked]", neoFormVersion))); + data.put("MC_SLIM", new LauncherDataEntry(String.format("[net.minecraft:client:%s:slim]", neoFormVersion), String.format("[net.minecraft:server:%s:slim]", neoFormVersion))); + data.put("MC_EXTRA", new LauncherDataEntry(String.format("[net.minecraft:client:%s:extra]", neoFormVersion), String.format("[net.minecraft:server:%s:extra]", neoFormVersion))); + data.put("MC_SRG", new LauncherDataEntry(String.format("[net.minecraft:client:%s:srg]", neoFormVersion), String.format("[net.minecraft:server:%s:srg]", neoFormVersion))); + data.put("PATCHED", new LauncherDataEntry(String.format("[%s:%s:%s:client]", "net.neoforged", "neoforge", getNeoForgeVersion().get()), String.format("[%s:%s:%s:server]", "net.neoforged", "neoforge", getNeoForgeVersion().get()))); + data.put("MCP_VERSION", new LauncherDataEntry(String.format("'%s'", neoFormVersion), String.format("'%s'", neoFormVersion))); + + var processors = new ArrayList(); + BiConsumer> commonProcessor = (processor, args) -> addProcessor(processors, null, processor, args); + BiConsumer> clientProcessor = (processor, args) -> addProcessor(processors, List.of("client"), processor, args); + BiConsumer> serverProcessor = (processor, args) -> addProcessor(processors, List.of("server"), processor, args); + + serverProcessor.accept(InstallerProcessor.INSTALLERTOOLS, + List.of("--task", "EXTRACT_FILES", "--archive", "{INSTALLER}", + + "--from", "data/run.sh", "--to", "{ROOT}/run.sh", "--exec", "{ROOT}/run.sh", + + "--from", "data/run.bat", "--to", "{ROOT}/run.bat", + + "--from", "data/user_jvm_args.txt", "--to", "{ROOT}/user_jvm_args.txt", "--optional", "{ROOT}/user_jvm_args.txt", + + "--from", "data/win_args.txt", "--to", "{ROOT}/libraries/net/neoforged/neoforge/%s/win_args.txt".formatted(getNeoForgeVersion().get()), + + "--from", "data/unix_args.txt", "--to", "{ROOT}/libraries/net/neoforged/neoforge/%s/unix_args.txt".formatted(getNeoForgeVersion().get())) + ); + serverProcessor.accept(InstallerProcessor.INSTALLERTOOLS, + List.of("--task", "BUNDLER_EXTRACT", "--input", "{MINECRAFT_JAR}", "--output", "{ROOT}/libraries/", "--libraries") + ); + serverProcessor.accept(InstallerProcessor.INSTALLERTOOLS, + List.of("--task", "BUNDLER_EXTRACT", "--input", "{MINECRAFT_JAR}", "--output", "{MC_UNPACKED}", "--jar-only") + ); + var neoformDependency = "net.neoforged:neoform:" + getMcAndNeoFormVersion().get() + "@zip";; + commonProcessor.accept(InstallerProcessor.INSTALLERTOOLS, + List.of("--task", "MCP_DATA", "--input", String.format("[%s]", neoformDependency), "--output", "{MAPPINGS}", "--key", "mappings") + ); + commonProcessor.accept(InstallerProcessor.INSTALLERTOOLS, + List.of("--task", "DOWNLOAD_MOJMAPS", "--version", getMinecraftVersion().get(), "--side", "{SIDE}", "--output", "{MOJMAPS}") + ); + commonProcessor.accept(InstallerProcessor.INSTALLERTOOLS, + List.of("--task", "MERGE_MAPPING", "--left", "{MAPPINGS}", "--right", "{MOJMAPS}", "--output", "{MERGED_MAPPINGS}", "--classes", "--fields", "--methods", "--reverse-right") + ); + clientProcessor.accept(InstallerProcessor.JARSPLITTER, + List.of("--input", "{MINECRAFT_JAR}", "--slim", "{MC_SLIM}", "--extra", "{MC_EXTRA}", "--srg", "{MERGED_MAPPINGS}") + ); + serverProcessor.accept(InstallerProcessor.JARSPLITTER, + List.of("--input", "{MC_UNPACKED}", "--slim", "{MC_SLIM}", "--extra", "{MC_EXTRA}", "--srg", "{MERGED_MAPPINGS}") + ); + // Note that the options supplied here have to match the ones used in the RemapJar task used to generate the binary patches + commonProcessor.accept(InstallerProcessor.FART, + List.of("--input", "{MC_SLIM}", "--output", "{MC_SRG}", "--names", "{MERGED_MAPPINGS}", "--ann-fix", "--ids-fix", "--src-fix", "--record-fix") + ); + commonProcessor.accept(InstallerProcessor.BINPATCHER, + List.of("--clean", "{MC_SRG}", "--output", "{PATCHED}", "--apply", "{BINPATCH}") + ); + + getLogger().info("Collecting libraries for Installer Profile"); + // Remove potential duplicates. + var libraryFilesToResolve = new LinkedHashMap(getLibraryFiles().get().size()); + for (var libraryFile : getLibraryFiles().get()) { + var existingFile = libraryFilesToResolve.putIfAbsent(libraryFile.getIdentifier().get(), libraryFile); + if (existingFile != null) { + var existing = existingFile.getFile().getAsFile().get(); + var duplicate = libraryFile.getFile().getAsFile().get(); + if (!existing.equals(duplicate)) { + throw new IllegalArgumentException("Cannot resolve installer profile! Library %s has different files: %s and %s.".formatted( + libraryFile.getIdentifier().get(), + existing, + duplicate)); + } + } + } + var libraries = new ArrayList<>( + LibraryCollector.resolveLibraries(getRepositoryURLs().get(), libraryFilesToResolve.values())); + + var universalJar = getUniversalJar().getAsFile().get().toPath(); + libraries.add(new Library( + "net.neoforged:neoforge:%s:universal".formatted(getNeoForgeVersion().get()), + new LibraryDownload(new LibraryArtifact( + LibraryCollector.sha1Hash(universalJar), + Files.size(universalJar), + "https://maven.neoforged.net/releases/net/neoforged/neoforge/%s/neoforge-%s-universal.jar".formatted( + getNeoForgeVersion().get(), + getNeoForgeVersion().get()), + "net/neoforged/neoforge/%s/neoforge-%s-universal.jar".formatted( + getNeoForgeVersion().get(), + getNeoForgeVersion().get()) + )))); + + var profile = new InstallerProfile( + "1", + "NeoForge", + "neoforge-%s".formatted(getNeoForgeVersion().get()), + icon, + getMinecraftVersion().get(), + "/version.json", + "/big_logo.png", + "Welcome to the simple NeoForge installer", + "https://mirrors.neoforged.net", + true, + data, + processors, + libraries, + "{LIBRARY_DIR}/net/minecraft/server/{MINECRAFT_VERSION}/server-{MINECRAFT_VERSION}.jar" + ); + + FileUtils.writeStringSafe( + getInstallerProfile().getAsFile().get().toPath(), + new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(profile), + StandardCharsets.UTF_8 + ); + } +} + +record InstallerProfile( + String spec, + String profile, + String version, + String icon, + String minecraft, + String json, + String logo, + String welcome, + String mirrorList, + boolean hideExtract, + Map data, + List processors, + List libraries, + String serverJarPath) {} + +record LauncherDataEntry( + String client, + String server) {} + +record ProcessorEntry( + @Nullable + List sides, + String jar, + List classpath, + List args) {} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java new file mode 100644 index 00000000000..59681903043 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java @@ -0,0 +1,130 @@ +package net.neoforged.neodev.installer; + +import com.google.gson.GsonBuilder; +import net.neoforged.neodev.utils.DependencyUtils; +import net.neoforged.neodev.utils.FileUtils; +import org.gradle.api.DefaultTask; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Nested; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +import javax.inject.Inject; +import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Creates the JSON file for running NeoForge via the Vanilla launcher. + */ +public abstract class CreateLauncherProfile extends DefaultTask { + @Inject + public CreateLauncherProfile() {} + + @Input + public abstract Property getFmlVersion(); + + @Input + public abstract Property getMinecraftVersion(); + + @Input + public abstract Property getNeoForgeVersion(); + + @Input + public abstract Property getRawNeoFormVersion(); + + @Nested + protected abstract ListProperty getLibraryFiles(); + + public void setLibraries(Configuration libraries) { + getLibraryFiles().set(IdentifiedFile.listFromConfiguration(getProject(), libraries)); + } + + @Input + public abstract ListProperty getRepositoryURLs(); + + @Input + public abstract ListProperty getIgnoreList(); + + @Input + protected abstract Property getModulePath(); + + public void setModules(Configuration modules) { + getModulePath().set(DependencyUtils.configurationToClasspath(modules, "${library_directory}/", "${classpath_separator}")); + } + + @OutputFile + public abstract RegularFileProperty getLauncherProfile(); + + @TaskAction + public void createLauncherProfile() throws IOException { + var time = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME); + + getLogger().info("Collecting libraries for Launcher Profile"); + var libraries = LibraryCollector.resolveLibraries(getRepositoryURLs().get(), getLibraryFiles().get()); + + var gameArguments = new ArrayList<>(List.of( + "--fml.neoForgeVersion", getNeoForgeVersion().get(), + "--fml.fmlVersion", getFmlVersion().get(), + "--fml.mcVersion", getMinecraftVersion().get(), + "--fml.neoFormVersion", getRawNeoFormVersion().get(), + "--launchTarget", "forgeclient")); + + var jvmArguments = new ArrayList<>(List.of( + "-Djava.net.preferIPv6Addresses=system", + "-DignoreList=" + String.join(",", getIgnoreList().get()), + "-DlibraryDirectory=${library_directory}")); + + jvmArguments.add("-p"); + jvmArguments.add(getModulePath().get()); + + jvmArguments.addAll(List.of( + "--add-modules", "ALL-MODULE-PATH", + "--add-opens", "java.base/java.util.jar=cpw.mods.securejarhandler", + "--add-opens", "java.base/java.lang.invoke=cpw.mods.securejarhandler", + "--add-exports", "java.base/sun.security.util=cpw.mods.securejarhandler", + "--add-exports", "jdk.naming.dns/com.sun.jndi.dns=java.naming")); + + var arguments = new LinkedHashMap>(); + arguments.put("game", gameArguments); + arguments.put("jvm", jvmArguments); + + var profile = new LauncherProfile( + "neoforge-%s".formatted(getNeoForgeVersion().get()), + time, + time, + "release", + "cpw.mods.bootstraplauncher.BootstrapLauncher", + getMinecraftVersion().get(), + arguments, + libraries + ); + + FileUtils.writeStringSafe( + getLauncherProfile().getAsFile().get().toPath(), + new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(profile), + StandardCharsets.UTF_8 + ); + } +} + +record LauncherProfile( + String id, + String time, + String releaseTime, + String type, + String mainClass, + String inheritsFrom, + Map> arguments, + List libraries) {} + diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/IdentifiedFile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/IdentifiedFile.java new file mode 100644 index 00000000000..a7f685236a0 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/IdentifiedFile.java @@ -0,0 +1,48 @@ +package net.neoforged.neodev.installer; + +import net.neoforged.neodev.utils.DependencyUtils; +import net.neoforged.neodev.utils.MavenIdentifier; +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.PathSensitive; +import org.gradle.api.tasks.PathSensitivity; + +import javax.inject.Inject; +import java.io.File; +import java.util.List; + +/** + * Combines a {@link File} and its {@link MavenIdentifier maven identifier}, + * for usage as task inputs that will be passed to {@link LibraryCollector}. + */ +abstract class IdentifiedFile { + static Provider> listFromConfiguration(Project project, Configuration configuration) { + return configuration.getIncoming().getArtifacts().getResolvedArtifacts().map( + artifacts -> artifacts.stream() + .map(artifact -> IdentifiedFile.of(project, artifact)) + .toList()); + } + + private static IdentifiedFile of(Project project, ResolvedArtifactResult resolvedArtifact) { + var identifiedFile = project.getObjects().newInstance(IdentifiedFile.class); + identifiedFile.getFile().set(resolvedArtifact.getFile()); + identifiedFile.getIdentifier().set(DependencyUtils.guessMavenIdentifier(resolvedArtifact)); + return identifiedFile; + } + + @Inject + public IdentifiedFile() {} + + @InputFile + @PathSensitive(PathSensitivity.NONE) + protected abstract RegularFileProperty getFile(); + + @Input + protected abstract Property getIdentifier(); +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/InstallerProcessor.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/InstallerProcessor.java new file mode 100644 index 00000000000..970fa6d1cbb --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/InstallerProcessor.java @@ -0,0 +1,19 @@ +package net.neoforged.neodev.installer; + +import net.neoforged.neodev.Tools; + +/** + * Identifies the tools used by the {@link InstallerProfile} to install NeoForge. + */ +public enum InstallerProcessor { + BINPATCHER(Tools.BINPATCHER), + FART(Tools.AUTO_RENAMING_TOOL), + INSTALLERTOOLS(Tools.INSTALLERTOOLS), + JARSPLITTER(Tools.JARSPLITTER); + + public final Tools tool; + + InstallerProcessor(Tools tool) { + this.tool = tool; + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/Library.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/Library.java new file mode 100644 index 00000000000..46669967f44 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/Library.java @@ -0,0 +1,3 @@ +package net.neoforged.neodev.installer; + +record Library(String name, LibraryDownload downloads) {} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryArtifact.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryArtifact.java new file mode 100644 index 00000000000..1e345980e9a --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryArtifact.java @@ -0,0 +1,7 @@ +package net.neoforged.neodev.installer; + +record LibraryArtifact( + String sha1, + long size, + String url, + String path) {} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java new file mode 100644 index 00000000000..7417ac14c33 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java @@ -0,0 +1,174 @@ +package net.neoforged.neodev.installer; + +import net.neoforged.neodev.utils.MavenIdentifier; +import org.gradle.api.logging.Logger; +import org.gradle.api.logging.Logging; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.DigestInputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HexFormat; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.function.Function; + +/** + * For each file in a collection, finds the repository that the file came from. + */ +class LibraryCollector { + public static List resolveLibraries(List repositoryUrls, Collection libraries) throws IOException { + var collector = new LibraryCollector(repositoryUrls); + for (var library : libraries) { + collector.addLibrary(library.getFile().getAsFile().get(), library.getIdentifier().get()); + } + + var result = collector.libraries.stream().map(future -> { + try { + return future.get(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).toList(); + LOGGER.info("Collected %d libraries".formatted(result.size())); + return result; + } + + private static final Logger LOGGER = Logging.getLogger(LibraryCollector.class); + /** + * Hosts from which we allow the installer to download. + * We whitelist here to avoid redirecting player download traffic to anyone not affiliated with Mojang or us. + */ + private static final List HOST_WHITELIST = List.of( + "minecraft.net", + "neoforged.net", + "mojang.com" + ); + + private static final URI MOJANG_MAVEN = URI.create("https://libraries.minecraft.net"); + private static final URI NEOFORGED_MAVEN = URI.create("https://maven.neoforged.net/releases"); + + private final List repositoryUrls; + + private final List> libraries = new ArrayList<>(); + + private final HttpClient httpClient = HttpClient.newBuilder().build(); + + private LibraryCollector(List repoUrl) { + this.repositoryUrls = new ArrayList<>(repoUrl); + + // Only remote repositories make sense (no maven local) + repositoryUrls.removeIf(it -> { + var lowercaseScheme = it.getScheme().toLowerCase(Locale.ROOT); + return !lowercaseScheme.equals("https") && !lowercaseScheme.equals("http"); + }); + // Allow only URLs from whitelisted hosts + repositoryUrls.removeIf(uri -> { + var lowercaseHost = uri.getHost().toLowerCase(Locale.ROOT); + return HOST_WHITELIST.stream().noneMatch(it -> lowercaseHost.equals(it) || lowercaseHost.endsWith("." + it)); + }); + // Always try Mojang Maven first, then our installer Maven + repositoryUrls.removeIf(it -> it.getHost().equals(MOJANG_MAVEN.getHost())); + repositoryUrls.removeIf(it -> it.getHost().equals(NEOFORGED_MAVEN.getHost()) && it.getPath().startsWith(NEOFORGED_MAVEN.getPath())); + repositoryUrls.add(0, NEOFORGED_MAVEN); + repositoryUrls.add(0, MOJANG_MAVEN); + + LOGGER.info("Collecting libraries from:"); + for (var repo : repositoryUrls) { + LOGGER.info(" - " + repo); + } + } + + private void addLibrary(File file, MavenIdentifier identifier) throws IOException { + final String name = identifier.artifactNotation(); + final String path = identifier.repositoryPath(); + + var sha1 = sha1Hash(file.toPath()); + var fileSize = Files.size(file.toPath()); + + // Try each configured repository in-order to find the file + CompletableFuture libraryFuture = null; + for (var repositoryUrl : repositoryUrls) { + var artifactUri = joinUris(repositoryUrl, path); + var request = HttpRequest.newBuilder(artifactUri) + .method("HEAD", HttpRequest.BodyPublishers.noBody()) + .build(); + + Function> makeRequest = (String previousError) -> { + return httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()) + .thenApply(response -> { + if (response.statusCode() != 200) { + LOGGER.info(" Got %d for %s".formatted(response.statusCode(), artifactUri)); + String message = "Could not find %s: %d".formatted(artifactUri, response.statusCode()); + // Prepend error message from previous repo if they all fail + if (previousError != null) { + message = previousError + "\n" + message; + } + throw new RuntimeException(message); + } + LOGGER.info(" Found %s -> %s".formatted(name, artifactUri)); + return new Library( + name, + new LibraryDownload(new LibraryArtifact( + sha1, + fileSize, + artifactUri.toString(), + path))); + }); + }; + + if (libraryFuture == null) { + libraryFuture = makeRequest.apply(null); + } else { + libraryFuture = libraryFuture.exceptionallyCompose(error -> { + return makeRequest.apply(error.getMessage()); + }); + } + } + + libraries.add(libraryFuture); + } + + static String sha1Hash(Path path) throws IOException { + MessageDigest digest; + try { + digest = MessageDigest.getInstance("SHA-1"); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + + try (var in = Files.newInputStream(path); + var din = new DigestInputStream(in, digest)) { + byte[] buffer = new byte[8192]; + while (din.read(buffer) != -1) { + } + } + + return HexFormat.of().formatHex(digest.digest()); + } + + private static URI joinUris(URI repositoryUrl, String path) { + var baseUrl = repositoryUrl.toString(); + if (baseUrl.endsWith("/") && path.startsWith("/")) { + while (path.startsWith("/")) { + path = path.substring(1); + } + return URI.create(baseUrl + path); + } else if (!baseUrl.endsWith("/") && !path.startsWith("/")) { + return URI.create(baseUrl + "/" + path); + } else { + return URI.create(baseUrl + path); + } + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryDownload.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryDownload.java new file mode 100644 index 00000000000..38afe5d0576 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryDownload.java @@ -0,0 +1,4 @@ +package net.neoforged.neodev.installer; + +record LibraryDownload( + LibraryArtifact artifact) {} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java b/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java new file mode 100644 index 00000000000..ee1bb651754 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java @@ -0,0 +1,84 @@ +package net.neoforged.neodev.utils; + +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; +import org.gradle.api.provider.Provider; +import org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public final class DependencyUtils { + private DependencyUtils() { + } + + /** + * Given a resolved artifact, try to guess which Maven GAV it was resolved from. + */ + public static MavenIdentifier guessMavenIdentifier(ResolvedArtifactResult result) { + String group; + String artifact; + String version; + String ext = ""; + String classifier = ""; + + var filename = result.getFile().getName(); + var startOfExt = filename.lastIndexOf('.'); + if (startOfExt != -1) { + ext = filename.substring(startOfExt + 1); + filename = filename.substring(0, startOfExt); + } + + if (result.getId() instanceof ModuleComponentArtifactIdentifier moduleId) { + group = moduleId.getComponentIdentifier().getGroup(); + artifact = moduleId.getComponentIdentifier().getModule(); + version = moduleId.getComponentIdentifier().getVersion(); + var expectedBasename = artifact + "-" + version; + + if (filename.startsWith(expectedBasename + "-")) { + classifier = filename.substring((expectedBasename + "-").length()); + } + } else { + // When we encounter a project reference, the component identifier does not expose the group or module name. + // But we can access the list of capabilities associated with the published variant the artifact originates from. + // If the capability was not overridden, this will be the project GAV. If it is *not* the project GAV, + // it will be at least in valid GAV format, not crashing NFRT when it parses the manifest. It will just be ignored. + var capabilities = result.getVariant().getCapabilities(); + if (capabilities.size() == 1) { + var capability = capabilities.get(0); + group = capability.getGroup(); + artifact = capability.getName(); + version = capability.getVersion(); + } else { + throw new IllegalArgumentException("Don't know how to break " + result.getId().getComponentIdentifier() + " into Maven components."); + } + } + return new MavenIdentifier(group, artifact, version, classifier, ext); + } + + /** + * Turns a configuration into a list of GAV entries. + */ + public static Provider> configurationToGavList(Configuration configuration) { + return configuration.getIncoming().getArtifacts().getResolvedArtifacts().map(results -> { + // Using .toList() fails with the configuration cache - looks like Gradle can't deserialize the resulting list? + return results.stream().map(artifact -> guessMavenIdentifier(artifact).artifactNotation()).collect(Collectors.toCollection(ArrayList::new)); + }); + } + + /** + * Turns a configuration into a classpath string, + * assuming that the contents of the configuration are installed following the Maven directory layout. + * + * @param prefix string to add in front of each classpath entry + * @param separator separator to add between each classpath entry + */ + public static Provider configurationToClasspath(Configuration configuration, String prefix, String separator) { + return configuration.getIncoming().getArtifacts().getResolvedArtifacts().map( + results -> results.stream() + .map(artifact -> prefix + guessMavenIdentifier(artifact).repositoryPath()) + .collect(Collectors.joining(separator)) + ); + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/utils/FileUtils.java b/buildSrc/src/main/java/net/neoforged/neodev/utils/FileUtils.java new file mode 100644 index 00000000000..d91996d32d7 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/utils/FileUtils.java @@ -0,0 +1,72 @@ +package net.neoforged.neodev.utils; + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.Charset; +import java.nio.file.AtomicMoveNotSupportedException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.List; + +public final class FileUtils { + private FileUtils() { + } + + public static void writeStringSafe(Path destination, String content, Charset charset) throws IOException { + if (!charset.newEncoder().canEncode(content)) { + throw new IllegalArgumentException("The given character set " + charset + + " cannot represent this string: " + content); + } + + try (var out = newSafeFileOutputStream(destination)) { + var encodedContent = content.getBytes(charset); + out.write(encodedContent); + } + } + + public static void writeLinesSafe(Path destination, List lines, Charset charset) throws IOException { + writeStringSafe(destination, String.join("\n", lines), charset); + } + + public static OutputStream newSafeFileOutputStream(Path destination) throws IOException { + var uniqueId = ProcessHandle.current().pid() + "." + Thread.currentThread().getId(); + + var tempFile = destination.resolveSibling(destination.getFileName().toString() + "." + uniqueId + ".tmp"); + var closed = new boolean[1]; + return new FilterOutputStream(Files.newOutputStream(tempFile)) { + @Override + public void close() throws IOException { + try { + super.close(); + if (!closed[0]) { + atomicMoveIfPossible(tempFile, destination); + } + } finally { + try { + Files.deleteIfExists(tempFile); + } catch (IOException ignored) { + } + closed[0] = true; + } + } + }; + } + + /** + * Atomically moves the given source file to the given destination file. + * If the atomic move is not supported, the file will be moved normally. + * + * @param source The source file + * @param destination The destination file + * @throws IOException If an I/O error occurs + */ + private static void atomicMoveIfPossible(final Path source, final Path destination) throws IOException { + try { + Files.move(source, destination, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); + } catch (AtomicMoveNotSupportedException ex) { + Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING); + } + } +} diff --git a/buildSrc/src/main/java/net/neoforged/neodev/utils/MavenIdentifier.java b/buildSrc/src/main/java/net/neoforged/neodev/utils/MavenIdentifier.java new file mode 100644 index 00000000000..6a22312fd09 --- /dev/null +++ b/buildSrc/src/main/java/net/neoforged/neodev/utils/MavenIdentifier.java @@ -0,0 +1,13 @@ +package net.neoforged.neodev.utils; + +import java.io.Serializable; + +public record MavenIdentifier(String group, String artifact, String version, String classifier, String extension) implements Serializable { + public String artifactNotation() { + return group + ":" + artifact + ":" + version + (classifier.isEmpty() ? "" : ":" + classifier) + ("jar".equals(extension) ? "" : "@" + extension); + } + + public String repositoryPath() { + return group.replace(".", "/") + "/" + artifact + "/" + version + "/" + artifact + "-" + version + (classifier.isEmpty() ? "" : "-" + classifier) + "." + extension; + } +} diff --git a/coremods/build.gradle b/coremods/build.gradle index 3d942a47012..127e7ec9dfc 100644 --- a/coremods/build.gradle +++ b/coremods/build.gradle @@ -5,15 +5,6 @@ plugins { id 'neoforge.formatting-conventions' } -repositories { - maven { url = 'https://maven.neoforged.net/releases' } - maven { - name 'Mojang' - url 'https://libraries.minecraft.net' - } - mavenCentral() -} - jar { manifest { attributes( diff --git a/coremods/settings.gradle b/coremods/settings.gradle new file mode 100644 index 00000000000..06c2cf68e4b --- /dev/null +++ b/coremods/settings.gradle @@ -0,0 +1,8 @@ +repositories { + maven { url = 'https://maven.neoforged.net/releases' } + maven { + name 'Mojang' + url 'https://libraries.minecraft.net' + } + mavenCentral() +} diff --git a/gradle.properties b/gradle.properties index f72f81dfb1c..c63cb9696ba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,14 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=true org.gradle.parallel=true org.gradle.caching=true -org.gradle.configuration-cache=false +org.gradle.configuration-cache=true org.gradle.debug=false +#org.gradle.warning.mode=fail + +# renovate: net.neoforged:moddev-gradle +moddevgradle_plugin_version=2.0.46-beta +# renovate: io.codechicken:DiffPatch +diffpatch_version=2.0.0.35 java_version=21 @@ -14,6 +20,14 @@ neoform_version=20240808.144430 # on snapshot versions, used to prefix the version neoforge_snapshot_next_stable=22.0 +# renovate: net.neoforged.jst:jst-cli-bundle +jst_version=1.0.45 +legacyinstaller_version=3.0.+ +# renovate: net.neoforged:AutoRenamingTool +art_version=2.0.3 +# renovate: net.neoforged.installertools:installertools +installertools_version=2.1.2 + mergetool_version=2.0.0 accesstransformers_version=10.0.1 coremods_version=6.0.4 @@ -22,7 +36,6 @@ modlauncher_version=11.0.4 securejarhandler_version=3.0.8 bootstraplauncher_version=2.0.2 asm_version=9.7 -installer_version=2.1.+ mixin_version=0.15.2+mixin.0.8.7 terminalconsoleappender_version=1.3.0 nightconfig_version=3.8.0 @@ -43,12 +56,8 @@ nashorn_core_version=15.3 lwjgl_glfw_version=3.3.2 mixin_extras_version=0.4.1 -jupiter_api_version=5.7.0 +jupiter_api_version=5.10.2 vintage_engine_version=5.+ assertj_core=3.25.1 neogradle.runtime.platform.installer.debug=true -# We want to be able to have a junit run disconnected from the test and main sourcesets -neogradle.subsystems.conventions.sourcesets.automatic-inclusion=false -neogradle.subsystems.conventions.enabled=false -neogradle.subsystems.tools.jst=net.neoforged.jst:jst-cli-bundle:1.0.45 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b415575..0aaefbcaf0f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/projects/base/build.gradle b/projects/base/build.gradle index 7a78b9aa79c..1a1f878f9a7 100644 --- a/projects/base/build.gradle +++ b/projects/base/build.gradle @@ -1,3 +1,15 @@ -dynamicProject { - neoform("${project.minecraft_version}-${project.neoform_version}") + +plugins { + id 'java-library' +} + +apply plugin: net.neoforged.neodev.NeoDevBasePlugin + +dependencies { + implementation("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { + capabilities { + requireCapability 'net.neoforged:neoform-dependencies' + } + endorseStrictVersions() + } } diff --git a/projects/neoforge/build.gradle b/projects/neoforge/build.gradle index 669b21be2a2..91177ff6910 100644 --- a/projects/neoforge/build.gradle +++ b/projects/neoforge/build.gradle @@ -10,6 +10,11 @@ plugins { id 'neoforge.versioning' } +apply plugin : net.neoforged.neodev.NeoDevPlugin + +// Because of the source set reference. +evaluationDependsOn(":neoforge-coremods") + gradleutils.setupSigning(project: project, signAllPublications: true) changelog { @@ -17,10 +22,15 @@ changelog { disableAutomaticPublicationRegistration() } -dynamicProject { - runtime("${project.minecraft_version}-${project.neoform_version}", - rootProject.layout.projectDirectory.dir('patches'), - rootProject.layout.projectDirectory.dir('rejects')) +sourceSets { + main { + java { + srcDirs rootProject.file('src/main/java') + } + resources { + srcDirs rootProject.file('src/main/resources'), rootProject.file('src/generated/resources') + } + } } final checkVersion = JCCPlugin.providePreviousVersion( @@ -29,7 +39,7 @@ final checkVersion = JCCPlugin.providePreviousVersion( ) final createCompatJar = tasks.register('createCompatibilityCheckJar', ProvideNeoForgeJarTask) { // Use the same jar that the patches were generated against - cleanJar.set(tasks.generateClientBinaryPatches.clean) + cleanJar.set(tasks.generateClientBinPatches.cleanJar) maven.set('https://maven.neoforged.net/releases') artifact.set('net.neoforged:neoforge') version.set(checkVersion) @@ -42,206 +52,110 @@ checkJarCompatibility { baseJar = createCompatJar.flatMap { it.output } } -installerProfile { - profile = 'NeoForge' +neoDev { + mods { + minecraft { + sourceSet sourceSets.main + } + "neoforge-coremods" { + sourceSet project(":neoforge-coremods").sourceSets.main + } + } } -minecraft { - // FML looks for this mod id to find the minecraft classes - modIdentifier 'minecraft' +dependencies { + // For an overview of what the nonstandard configurations do, + // have a look at NeoDevConfigurations.java in the buildSrc folder. - accessTransformers { - file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') + neoFormData("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { + capabilities { + requireCapability 'net.neoforged:neoform' + } + endorseStrictVersions() } -} - -tasks.configureEach { tsk -> - if (tsk.name == 'neoFormApplyUserAccessTransformer' && project.hasProperty('validateAccessTransformers')) { - tsk.inputs.property('validation', 'error') - tsk.logLevel('ERROR') - tsk.doFirst { - tsk.getRuntimeProgramArguments().addAll(tsk.getRuntimeProgramArguments().get()) - tsk.getRuntimeProgramArguments().add('--access-transformer-validation=error') + neoFormDependencies("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { + capabilities { + requireCapability 'net.neoforged:neoform-dependencies' } + endorseStrictVersions() } -} -sourceSets { - main { - java { - srcDirs rootProject.file('src/main/java') - } - resources { - srcDirs rootProject.file('src/main/resources'), rootProject.file('src/generated/resources') + moduleLibraries "cpw.mods:securejarhandler:${project.securejarhandler_version}" + for (var asmModule : ["org.ow2.asm:asm", "org.ow2.asm:asm-commons", "org.ow2.asm:asm-tree", "org.ow2.asm:asm-util", "org.ow2.asm:asm-analysis"]) { + moduleLibraries(asmModule) { + // Vanilla ships with ASM 9.3 transitively (via their OpenID connect library dependency), we require + // ASM in a more recent version and have to strictly require this to override the strict Minecraft version. + version { + strictly project.asm_version + } } } -} + moduleLibraries "cpw.mods:bootstraplauncher:${project.bootstraplauncher_version}" + moduleLibraries "net.neoforged:JarJarFileSystems:${project.jarjar_version}" -dependencies { - runtimeOnly "cpw.mods:bootstraplauncher:${project.bootstraplauncher_version}" - - moduleOnly "cpw.mods:securejarhandler:${project.securejarhandler_version}" - moduleOnly "org.ow2.asm:asm:${project.asm_version}" - moduleOnly "org.ow2.asm:asm-commons:${project.asm_version}" - moduleOnly "org.ow2.asm:asm-tree:${project.asm_version}" - moduleOnly "org.ow2.asm:asm-util:${project.asm_version}" - moduleOnly "org.ow2.asm:asm-analysis:${project.asm_version}" - moduleOnly "cpw.mods:bootstraplauncher:${project.bootstraplauncher_version}" - moduleOnly "net.neoforged:JarJarFileSystems:${project.jarjar_version}" - - installer ("net.neoforged.fancymodloader:loader:${project.fancy_mod_loader_version}") { + libraries ("net.neoforged.fancymodloader:loader:${project.fancy_mod_loader_version}") { exclude group: 'org.slf4j' exclude group: 'net.fabricmc' } - installer ("net.neoforged.fancymodloader:earlydisplay:${project.fancy_mod_loader_version}") { + libraries ("net.neoforged.fancymodloader:earlydisplay:${project.fancy_mod_loader_version}") { exclude group: 'org.lwjgl' exclude group: 'org.slf4j' exclude group: 'net.fabricmc' } - installer "cpw.mods:securejarhandler:${project.securejarhandler_version}" - installer "org.ow2.asm:asm:${project.asm_version}" - installer "org.ow2.asm:asm-commons:${project.asm_version}" - installer "org.ow2.asm:asm-tree:${project.asm_version}" - installer "org.ow2.asm:asm-util:${project.asm_version}" - installer "org.ow2.asm:asm-analysis:${project.asm_version}" - installer "net.neoforged:accesstransformers:${project.accesstransformers_version}" - installer "net.neoforged:bus:${project.eventbus_version}" - installer "net.neoforged:coremods:${project.coremods_version}" - installer "cpw.mods:modlauncher:${project.modlauncher_version}" - installer "net.neoforged:mergetool:${project.mergetool_version}:api" - installer "com.electronwill.night-config:core:${project.nightconfig_version}" - installer "com.electronwill.night-config:toml:${project.nightconfig_version}" - installer "org.apache.maven:maven-artifact:${project.apache_maven_artifact_version}" - installer "net.jodah:typetools:${project.typetools_version}" - installer "net.minecrell:terminalconsoleappender:${project.terminalconsoleappender_version}" - installer("net.fabricmc:sponge-mixin:${project.mixin_version}") { transitive = false } - installer "org.openjdk.nashorn:nashorn-core:${project.nashorn_core_version}" - installer ("net.neoforged:JarJarSelector:${project.jarjar_version}") { + libraries "net.neoforged:accesstransformers:${project.accesstransformers_version}" + libraries "net.neoforged:bus:${project.eventbus_version}" + libraries "net.neoforged:coremods:${project.coremods_version}" + libraries "cpw.mods:modlauncher:${project.modlauncher_version}" + libraries "net.neoforged:mergetool:${project.mergetool_version}:api" + libraries "com.electronwill.night-config:core:${project.nightconfig_version}" + libraries "com.electronwill.night-config:toml:${project.nightconfig_version}" + libraries "org.apache.maven:maven-artifact:${project.apache_maven_artifact_version}" + libraries "net.jodah:typetools:${project.typetools_version}" + libraries "net.minecrell:terminalconsoleappender:${project.terminalconsoleappender_version}" + libraries("net.fabricmc:sponge-mixin:${project.mixin_version}") { transitive = false } + libraries "org.openjdk.nashorn:nashorn-core:${project.nashorn_core_version}" + libraries ("net.neoforged:JarJarSelector:${project.jarjar_version}") { exclude group: 'org.slf4j' } // We depend on apache commons directly as there is a difference between the version the server uses and the one the client does - installer "org.apache.commons:commons-lang3:${project.apache_commons_lang3_version}" - installer ("net.neoforged:JarJarMetadata:${project.jarjar_version}") { + libraries "org.apache.commons:commons-lang3:${project.apache_commons_lang3_version}" + libraries ("net.neoforged:JarJarMetadata:${project.jarjar_version}") { exclude group: 'org.slf4j' } - // Manually override log4j since the version coming from other `installer` dependencies is outdated - installer "org.apache.logging.log4j:log4j-api:${project.log4j_version}" - installer "org.apache.logging.log4j:log4j-core:${project.log4j_version}" compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}" - userdevCompileOnly jarJar("io.github.llamalad7:mixinextras-neoforge:${project.mixin_extras_version}"), { - jarJar.ranged(it, "[${project.mixin_extras_version},)") - } - - userdevTestImplementation("net.neoforged.fancymodloader:junit-fml:${project.fancy_mod_loader_version}") - compileOnly(jarJar(project(":neoforge-coremods"))) -} - -runTypes { - client { - singleInstance false - client true - - arguments.addAll '--fml.neoForgeVersion', project.version - arguments.addAll '--fml.fmlVersion', project.fancy_mod_loader_version - arguments.addAll '--fml.mcVersion', project.minecraft_version - arguments.addAll '--fml.neoFormVersion', project.neoform_version - } - - server { - server true - - arguments.addAll '--fml.neoForgeVersion', project.version - arguments.addAll '--fml.fmlVersion', project.fancy_mod_loader_version - arguments.addAll '--fml.mcVersion', project.minecraft_version - arguments.addAll '--fml.neoFormVersion', project.neoform_version - } - - gameTestServer { - from project.runTypes.server - - gameTest true - } - - gameTestClient { - from project.runTypes.client - - gameTest true - } - - data { - dataGenerator true + userdevCompileOnly jarJar("io.github.llamalad7:mixinextras-neoforge:${project.mixin_extras_version}") - // Don't set modid here so we can reuse this runType for test datagen - arguments.addAll '--fml.neoForgeVersion', project.version - arguments.addAll '--fml.fmlVersion', project.fancy_mod_loader_version - arguments.addAll '--fml.mcVersion', project.minecraft_version - arguments.addAll '--fml.neoFormVersion', project.neoform_version + userdevTestFixtures("net.neoforged.fancymodloader:junit-fml:${project.fancy_mod_loader_version}") { + endorseStrictVersions() } - junit { - junit true - arguments.addAll '--fml.neoForgeVersion', project.version - arguments.addAll '--fml.fmlVersion', project.fancy_mod_loader_version - arguments.addAll '--fml.mcVersion', project.minecraft_version - arguments.addAll '--fml.neoFormVersion', project.neoform_version - } + // Must be implementation instead of compileOnly so that running dependent projects such as tests will trigger (re)compilation of coremods. + // (Only needed when compiling through IntelliJ non-delegated builds - otherwise `compileOnly` would work). + implementation(jarJar(project(":neoforge-coremods"))) } -runs { - client { } - server { } - gameTestServer { } - gameTestClient { } - data { - arguments.addAll '--mod', 'neoforge' - - modSources.add project.sourceSets.main - - idea { - primarySourceSet project.sourceSets.main +neoDev { + runs { + client { + client() + } + server { + server() + } + gameTestServer { + type = "gameTestServer" + } + data { + data() + programArguments.addAll '--mod', 'neoforge', '--flat', '--all', '--validate', + '--existing', rootProject.file("src/main/resources").absolutePath, + '--output', rootProject.file("src/generated/resources").absolutePath } } } -runs.configureEach { it -> - modSources.add project(":neoforge-coremods").sourceSets.main - - final File gameDir = project.file("run/${it.name}") as File - gameDir.mkdirs(); - - it.workingDirectory.set gameDir - it.arguments.addAll '--gameDir', gameDir.absolutePath -} - -launcherProfile { - arguments { - game '--fml.neoForgeVersion' - game project.version - game '--fml.fmlVersion' - game project.fancy_mod_loader_version - game '--fml.mcVersion' - game project.minecraft_version - game '--fml.neoFormVersion' - game project.neoform_version - } -} - -userdevProfile { - runTypes.configureEach { - argument '--fml.neoForgeVersion' - argument project.version - argument '--fml.fmlVersion' - argument project.fancy_mod_loader_version - argument '--fml.mcVersion' - argument project.minecraft_version - argument '--fml.neoFormVersion' - argument project.neoform_version - } - additionalTestDependencyArtifactCoordinate "net.neoforged:testframework:${project.version}" -} - tasks.withType(Javadoc.class).configureEach { options.tags = [ 'apiNote:a:API Note:', @@ -251,27 +165,6 @@ tasks.withType(Javadoc.class).configureEach { options.addStringOption('Xdoclint:all,-missing', '-public') } -configurations { - forValidation { - canBeConsumed = true - canBeResolved = false - attributes { - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) - attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) - attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR)) - } - - extendsFrom api, runtimeOnly - } -} - -artifacts { - forValidation(jar.archiveFile) { - builtBy(jar) - } -} - AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.components.findByName("java") // Ensure the two default variants are not published, since they // contain Minecraft classes @@ -282,10 +175,12 @@ javaComponent.withVariantsFromConfiguration(configurations.runtimeElements) { it.skip() } +// Resolvable configurations only configurations { modDevBundle { + canBeDeclared = false canBeResolved = false - canBeConsumed = true + extendsFrom neoFormData attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "data")) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -296,8 +191,8 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} // Publish it } modDevConfig { + canBeDeclared = false canBeResolved = false - canBeConsumed = true attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "data")) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -308,8 +203,8 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} // Publish it } installerJar { + canBeDeclared = false canBeResolved = false - canBeConsumed = true attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) @@ -324,8 +219,8 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} } universalJar { + canBeDeclared = false canBeResolved = false - canBeConsumed = true attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) @@ -337,8 +232,8 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} } changelog { + canBeDeclared = false canBeResolved = false - canBeConsumed = true attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "changelog")) @@ -349,11 +244,9 @@ configurations { } } modDevApiElements { + canBeDeclared = false canBeResolved = false - canBeConsumed = true - afterEvaluate { - extendsFrom userdevCompileOnly, installerLibraries, moduleOnly - } + extendsFrom libraries, moduleLibraries, userdevCompileOnly, neoFormDependencies attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -365,11 +258,9 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} } modDevRuntimeElements { + canBeDeclared = false canBeResolved = false - canBeConsumed = true - afterEvaluate { - extendsFrom installerLibraries, moduleOnly - } + extendsFrom libraries, moduleLibraries, neoFormDependencies attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -381,11 +272,9 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} } modDevModulePath { + canBeDeclared = false canBeResolved = false - canBeConsumed = true - afterEvaluate { - extendsFrom moduleOnly - } + extendsFrom moduleLibraries attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -396,8 +285,9 @@ configurations { javaComponent.addVariantsFromConfiguration(it) {} } modDevTestFixtures { + canBeDeclared = false canBeResolved = false - canBeConsumed = true + extendsFrom userdevTestFixtures attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -410,63 +300,35 @@ configurations { } } -dependencies { - modDevBundle("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { - capabilities { - requireCapability 'net.neoforged:neoform' - } - endorseStrictVersions() - } - modDevApiElements("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { - capabilities { - requireCapability 'net.neoforged:neoform-dependencies' - } - endorseStrictVersions() - } - modDevRuntimeElements("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { - capabilities { - requireCapability 'net.neoforged:neoform-dependencies' - } - endorseStrictVersions() - } - modDevTestFixtures("net.neoforged.fancymodloader:junit-fml:${project.fancy_mod_loader_version}") { - endorseStrictVersions() - } -} - processResources { inputs.property("version", project.version) + final version = project.version filesMatching("META-INF/neoforge.mods.toml") { expand([ "global": [ - "neoForgeVersion": project.version + "neoForgeVersion": version ] ]) } } -afterEvaluate { - artifacts { - modDevBundle(userdevJar) { - setClassifier("userdev") // Legacy - } - modDevConfig(createUserdevJson.output) { - builtBy(createUserdevJson) - setClassifier("moddev-config") - } - universalJar(signUniversalJar.output) { - builtBy(signUniversalJar) - setClassifier("universal") - } - installerJar(signInstallerJar.output) { - builtBy(signInstallerJar) - setClassifier("installer") - } - changelog(createChangelog.outputFile) { - builtBy(createChangelog) - setClassifier("changelog") - setExtension("txt") - } +artifacts { + modDevBundle(userdevJar) { + setClassifier("userdev") // Legacy + } + modDevConfig(writeUserDevConfig.userDevConfig) { + setClassifier("moddev-config") + } + universalJar(universalJar) { + setClassifier("universal") + } + installerJar(installerJar) { + setClassifier("installer") + } + changelog(createChangelog.outputFile) { + builtBy(createChangelog) + setClassifier("changelog") + setExtension("txt") } } diff --git a/settings.gradle b/settings.gradle index 4049a3edc6f..aff93fdd4ca 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,13 +1,28 @@ pluginManagement { repositories { gradlePluginPortal() - mavenLocal() maven { url = 'https://maven.neoforged.net/releases' } + mavenLocal() } } plugins { - id 'net.neoforged.gradle.platform' version '7.0.163' + id 'net.neoforged.moddev.repositories' version "${moddevgradle_plugin_version}" + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' +} + +// This makes the version available to buildSrc +gradle.ext.moddevgradle_plugin_version = moddevgradle_plugin_version +gradle.ext.gson_version = gson_version +gradle.ext.diffpatch_version = diffpatch_version + +dependencyResolutionManagement { + repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS + rulesMode = RulesMode.FAIL_ON_PROJECT_RULES + repositories { + mavenCentral() + mavenLocal() + } } if (rootProject.name.toLowerCase() == "neoforge") { @@ -15,13 +30,10 @@ if (rootProject.name.toLowerCase() == "neoforge") { rootProject.name = "NeoForge-Root" } -dynamicProjects { - include ':base' - include ':neoforge' - - project(":base").projectDir = file("projects/base") - project(":neoforge").projectDir = file("projects/neoforge") -} +include ':base' +project(':base').projectDir = file('projects/base') +include ':neoforge' +project(':neoforge').projectDir = file('projects/neoforge') include ':tests' project(":tests").projectDir = file("tests") diff --git a/testframework/build.gradle b/testframework/build.gradle index 91a01c1c760..d5d98b4059a 100644 --- a/testframework/build.gradle +++ b/testframework/build.gradle @@ -3,25 +3,19 @@ plugins { id 'maven-publish' id 'com.diffplug.spotless' id 'net.neoforged.licenser' - id 'net.neoforged.gradle.platform' id 'neoforge.formatting-conventions' } java.withSourcesJar() -repositories { - maven { - name 'Mojang' - url 'https://libraries.minecraft.net' - } - maven { - name 'NeoForged' - url 'https://maven.neoforged.net/releases' - } -} +apply plugin : net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin dependencies { - implementation project(path: ':neoforge', configuration: 'runtimeElements') + // TODO: is this leaking in the POM? (most likely yes) + // TODO: does this need to be changed back to runtimeDependencies? + // TODO: should use attributes to resolve the right variant instead of hardcoding + compileOnly project(path: ':neoforge', configuration: 'apiElements') + runtimeOnly project(path: ':neoforge', configuration: 'runtimeElements') compileOnly(platform("org.junit:junit-bom:${project.jupiter_api_version}")) compileOnly "org.junit.jupiter:junit-jupiter-params" @@ -30,6 +24,14 @@ dependencies { compileOnly "com.google.code.findbugs:jsr305:3.0.2" } +sourceSets { + main { + // TODO: cursed + compileClasspath += project(':neoforge').sourceSets.main.compileClasspath + runtimeClasspath += project(':neoforge').sourceSets.main.runtimeClasspath + } +} + license { header = rootProject.file('codeformat/HEADER.txt') include '**/*.java' @@ -39,6 +41,7 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } +def version = project.version tasks.withType(ProcessResources).configureEach { inputs.properties version: version diff --git a/tests/build.gradle b/tests/build.gradle index 2da20a4e402..1a528210c69 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -1,27 +1,18 @@ plugins { id 'java' - id 'net.neoforged.gradle.platform' id 'com.diffplug.spotless' id 'net.neoforged.licenser' id 'neoforge.formatting-conventions' } +apply plugin : net.neoforged.neodev.NeoDevExtraPlugin + +evaluationDependsOn(":neoforge") + def neoforgeProject = project(':neoforge') def testframeworkProject = project(':testframework') def coremodsProject = project(':neoforge-coremods') -repositories { - mavenLocal() - maven { - name 'Mojang' - url 'https://libraries.minecraft.net' - } - maven { - name 'NeoForged' - url 'https://maven.neoforged.net/releases' - } -} - sourceSets { main { resources { @@ -31,10 +22,6 @@ sourceSets { junit {} } -configurations { - junitImplementation.extendsFrom(implementation) -} - dependencies { implementation project(path: ':neoforge', configuration: 'runtimeElements') implementation(testframeworkProject) @@ -45,74 +32,79 @@ dependencies { junitImplementation("org.assertj:assertj-core:${project.assertj_core}") junitImplementation "net.neoforged.fancymodloader:junit-fml:${project.fancy_mod_loader_version}" + junitImplementation project(path: ':neoforge', configuration: 'runtimeElements') + junitImplementation(testframeworkProject) compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}" } -runs { - client { - configure neoforgeProject.runTypes.client - } - junit { - configure neoforgeProject.runTypes.junit - unitTestSource sourceSets.junit - } - server { - configure neoforgeProject.runTypes.server - } - gameTestServer { - configure neoforgeProject.runTypes.gameTestServer - } - gameTestClient { - configure neoforgeProject.runTypes.gameTestClient +junitTest { + useJUnitPlatform() + classpath = sourceSets.junit.output + sourceSets.junit.runtimeClasspath + testClassesDirs = sourceSets.junit.output.classesDirs + outputs.upToDateWhen { false } +} + +neoDev { + mods { + neotests { + sourceSet sourceSets.main + } + testframework { + sourceSet project(":testframework").sourceSets.main + } + junit { + sourceSet sourceSets.junit + } + coremods { + sourceSet coremodsProject.sourceSets.main + } } - data { - configure neoforgeProject.runTypes.data - - arguments.addAll '--flat', '--all', '--validate', - '--mod', 'data_gen_test', - '--mod', 'global_loot_test', - '--mod', 'scaffolding_test', - '--mod', 'custom_tag_types_test', - '--mod', 'new_model_loader_test', - '--mod', 'remove_tag_datagen_test', - '--mod', 'tag_based_tool_types', - '--mod', 'custom_transformtype_test', - '--mod', 'data_pack_registries_test', - '--mod', 'biome_modifiers_test', - '--mod', 'structure_modifiers_test', - '--mod', 'custom_preset_editor_test', - '--mod', 'custom_predicate_test', - '--mod', 'neotests', - '--existing-mod', 'testframework', - '--existing', sourceSets.main.resources.srcDirs[0].absolutePath - - final File gameDir = project.file("runs/${name}") as File - gameDir.mkdirs(); - - workingDirectory.set gameDir - arguments.addAll '--gameDir', gameDir.absolutePath + + runs { + client { + client() + } + server { + server() + } + gameTestServer { + type = "gameTestServer" + } + data { + data() + + programArguments.addAll '--flat', '--all', '--validate', + '--mod', 'data_gen_test', + '--mod', 'global_loot_test', + '--mod', 'scaffolding_test', + '--mod', 'custom_tag_types_test', + '--mod', 'new_model_loader_test', + '--mod', 'remove_tag_datagen_test', + '--mod', 'tag_based_tool_types', + '--mod', 'custom_transformtype_test', + '--mod', 'data_pack_registries_test', + '--mod', 'biome_modifiers_test', + '--mod', 'structure_modifiers_test', + '--mod', 'custom_preset_editor_test', + '--mod', 'custom_predicate_test', + '--mod', 'neotests', + '--existing-mod', 'testframework', + '--existing', project.file("src/main/resources").absolutePath, + '--output', project.file("src/generated/resources").absolutePath + } } -} -//We need the assets and natives tasks from the forge project. -runs.configureEach { - dependsOn.add(neoforgeProject.runtime.assets) - dependsOn.add(neoforgeProject.runtime.natives) - modSource neoforgeProject.sourceSets.main - modSource coremodsProject.sourceSets.main - modSource testframeworkProject.sourceSets.main -} + runs.configureEach { + // Add NeoForge and Minecraft (both under the "minecraft" mod), and exclude junit. + loadedMods = [neoforgeProject.neoDev.mods.minecraft, mods.neotests, mods.testframework, mods.coremods] -afterEvaluate { - runs.data { - // Override --output that forge already has - def args = new ArrayList(arguments.get()); - def outputIndex = args.indexOf('--output'); - args.set(outputIndex+1, file('src/generated/resources/').absolutePath); - arguments.set(args); + gameDirectory.set project.file("runs/${it.name}") as File } - runs.junit.modSources.all().get().values().remove(sourceSets.main) +} + +neoDevTest { + loadedMods = [ project(":neoforge").neoDev.mods.minecraft, neoDev.mods.testframework, neoDev.mods.coremods, neoDev.mods.junit ] } license { From b43e04c698fc4c99488304573d10bd5086e3d7f3 Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:26:17 +0100 Subject: [PATCH 03/13] Add Vanilla runs in NeoForge development environment and give each run its own folder (#1697) Co-authored-by: Sebastian Hartte --- .../neoforged/neodev/NeoDevBasePlugin.java | 38 ++++++++++++++++++- docs/CONTRIBUTING.md | 7 +++- gradle.properties | 2 +- projects/base/.gitignore | 1 + projects/base/build.gradle | 19 ++++++++++ projects/neoforge/build.gradle | 3 ++ tests/build.gradle | 3 ++ 7 files changed, 69 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java index 7680fffa9f7..c6e3e8ea6dd 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java @@ -1,9 +1,12 @@ package net.neoforged.neodev; import net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin; +import net.neoforged.moddevgradle.internal.NeoDevFacade; import net.neoforged.nfrtgradle.CreateMinecraftArtifacts; +import net.neoforged.nfrtgradle.DownloadAssets; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.tasks.Sync; public class NeoDevBasePlugin implements Plugin { @@ -12,13 +15,46 @@ public void apply(Project project) { // These plugins allow us to declare dependencies on Minecraft libraries needed to compile the official sources project.getPlugins().apply(MinecraftDependenciesPlugin.class); + var dependencyFactory = project.getDependencyFactory(); + var tasks = project.getTasks(); + var neoDevBuildDir = project.getLayout().getBuildDirectory().dir("neodev"); + + var extension = project.getExtensions().create(NeoDevExtension.NAME, NeoDevExtension.class); + var createSources = NeoDevPlugin.configureMinecraftDecompilation(project); + // Task must run on sync to have MC resources available for IDEA nondelegated builds. + NeoDevFacade.runTaskOnProjectSync(project, createSources); - project.getTasks().register("setup", Sync.class, task -> { + tasks.register("setup", Sync.class, task -> { task.setGroup(NeoDevPlugin.GROUP); task.setDescription("Replaces the contents of the base project sources with the unpatched, decompiled Minecraft source code."); task.from(project.zipTree(createSources.flatMap(CreateMinecraftArtifacts::getSourcesArtifact))); task.into(project.file("src/main/java/")); }); + + var downloadAssets = tasks.register("downloadAssets", DownloadAssets.class, task -> { + task.setGroup(NeoDevPlugin.INTERNAL_GROUP); + task.getNeoFormArtifact().set(createSources.flatMap(CreateMinecraftArtifacts::getNeoFormArtifact)); + task.getAssetPropertiesFile().set(neoDevBuildDir.map(dir -> dir.file("minecraft_assets.properties"))); + }); + + // MC looks for its resources on the classpath. + var runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME); + runtimeClasspath.getDependencies().add( + dependencyFactory.create( + project.files(createSources.flatMap(CreateMinecraftArtifacts::getResourcesArtifact)) + ) + ); + NeoDevFacade.setupRuns( + project, + neoDevBuildDir, + extension.getRuns(), + // Pass an empty file collection for the userdev config. + // This will cause MDG to generate a dummy config suitable for vanilla. + project.files(), + modulePath -> {}, + legacyClasspath -> {}, + downloadAssets.flatMap(DownloadAssets::getAssetPropertiesFile) + ); } } diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index eea2cf6d4b3..41b36415464 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -19,8 +19,11 @@ Contributing to NeoForge 8. Modify the patched Minecraft sources in `projects/neoforge/src/main/java` as needed. The unmodified sources are available in `projects/base/src/main/java` for your reference. Do not modify these. 9. Test your changes - Run the game (Runs are available in the IDE) - - Run `gradlew :tests:runGameTestServer` or `Tests: GameTestServer` from IDE - - Run `gradlew :tests:runGameTestClient` or `Tests: GameTestClient` from IDE + - Runs starting with `base -` run Vanilla without NeoForge or its patches. + - Runs starting with `neoforge -` run NeoForge. + - Runs starting with `tests -` run NeoForge along with the test mods in the `tests` project. + - Run `gradlew :tests:runGameTestServer` or `tests - GameTestServer` from IDE + - Run `gradlew :tests:runClient` or `tests - Client` from IDE - If possible, write an automated test under the tests project. See [NEOGAMETESTS.md](NEOGAMETESTS.md) for more info. 10. Run `gradlew unpackSourcePatches` to generate patch-files from the patched sources 11. Run `gradlew applyAllFormatting` to automatically format sources diff --git a/gradle.properties b/gradle.properties index c63cb9696ba..f37ccd95425 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.debug=false #org.gradle.warning.mode=fail # renovate: net.neoforged:moddev-gradle -moddevgradle_plugin_version=2.0.46-beta +moddevgradle_plugin_version=2.0.47-beta # renovate: io.codechicken:DiffPatch diffpatch_version=2.0.0.35 diff --git a/projects/base/.gitignore b/projects/base/.gitignore index 1b10a46d0a1..cb56563da33 100644 --- a/projects/base/.gitignore +++ b/projects/base/.gitignore @@ -1,3 +1,4 @@ src build .gradle +run diff --git a/projects/base/build.gradle b/projects/base/build.gradle index 1a1f878f9a7..04cca6fe08d 100644 --- a/projects/base/build.gradle +++ b/projects/base/build.gradle @@ -13,3 +13,22 @@ dependencies { endorseStrictVersions() } } + +neoDev { + runs { + configureEach { + gameDirectory = layout.projectDir.dir("run/$name") + } + client { + client() + } + server { + server() + } + // Generated files are in run/data/generated + data { + data() + programArgument "--all" + } + } +} diff --git a/projects/neoforge/build.gradle b/projects/neoforge/build.gradle index 91177ff6910..3912a5bd300 100644 --- a/projects/neoforge/build.gradle +++ b/projects/neoforge/build.gradle @@ -138,6 +138,9 @@ dependencies { neoDev { runs { + configureEach { + gameDirectory = layout.projectDir.dir("run/$name") + } client { client() } diff --git a/tests/build.gradle b/tests/build.gradle index 1a528210c69..37ea199d5bc 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -62,6 +62,9 @@ neoDev { } runs { + configureEach { + gameDirectory = layout.projectDir.dir("run/$name") + } client { client() } From d98dd0595988339a2d2eeb4a327ccfd91cc58de7 Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+technici4n@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:19:39 +0100 Subject: [PATCH 04/13] Add ${version_name}.jar to the prod client ignoreList, fixes crashes with some launchers (#1718) --- buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java index e7f9f779342..952d1686741 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java @@ -251,7 +251,8 @@ public void apply(Project project) { } return repos; })); - task.getIgnoreList().addAll("client-extra", "neoforge-"); + // ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar. + task.getIgnoreList().addAll("client-extra", "${version_name}.jar"); task.setModules(configurations.modulePath); task.getLauncherProfile().set(neoDevBuildDir.map(dir -> dir.file("launcher-profile.json"))); }); From 020a373364251e2d53b1574231d75b3da9da42f3 Mon Sep 17 00:00:00 2001 From: shartte Date: Tue, 3 Dec 2024 20:28:05 +0100 Subject: [PATCH 05/13] Fix JSON type of "spec" field in installer profile JSON (#1723) (#1727) --- .../neoforged/neodev/installer/CreateInstallerProfile.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java index 3b745f744aa..c9da8c83ec5 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java @@ -178,7 +178,7 @@ public void createInstallerProfile() throws IOException { )))); var profile = new InstallerProfile( - "1", + 1, "NeoForge", "neoforge-%s".formatted(getNeoForgeVersion().get()), icon, @@ -203,7 +203,7 @@ public void createInstallerProfile() throws IOException { } record InstallerProfile( - String spec, + int spec, String profile, String version, String icon, From 07891664b8b85cb5a8c4da602b27810ec7003c9a Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Fri, 13 Dec 2024 14:40:08 -0600 Subject: [PATCH 06/13] Switch out Spotless for Immaculate, an alternative formatting plugin (#1530) --- build.gradle | 14 ++++----- .../neoforge.formatting-conventions.gradle | 31 ++++++++++--------- coremods/build.gradle | 1 - docs/CONTRIBUTING.md | 2 +- testframework/build.gradle | 1 - tests/build.gradle | 1 - 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index fbc90b7d61c..707385ed1a9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import java.util.regex.Pattern plugins { id 'net.neoforged.gradleutils' version '3.0.0' - id 'com.diffplug.spotless' version '6.22.0' apply false + id 'dev.lukebemish.immaculate' version '0.1.6' apply false id 'net.neoforged.licenser' version '0.7.5' id 'neoforge.formatting-conventions' id 'neoforge.versioning' @@ -56,14 +56,14 @@ license { } // Put spotless here because it wants the files to live inside the project root -spotless { - java { - target rootProject.fileTree("src", { +immaculate { + workflows.named("java") { + files.from rootProject.fileTree("src", { include "**/*.java" }) } - format 'patches', { - target rootProject.fileTree("patches") + workflows.register("patches") { + files.from(rootProject.fileTree("patches")) custom 'noImportChanges', { String fileContents -> if (fileContents.contains('+import') || fileContents.contains('-import')) { @@ -152,7 +152,5 @@ spotless { custom 'jetbrainsNullablePatches', { String fileContents -> fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable') } - - bumpThisNumberIfACustomStepChanges(5) } } diff --git a/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle b/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle index e0f554b8205..0a26b947823 100644 --- a/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle +++ b/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle @@ -1,6 +1,6 @@ import java.util.regex.Matcher -project.plugins.apply('com.diffplug.spotless') +project.plugins.apply('dev.lukebemish.immaculate') abstract class GeneratePackageInfos extends DefaultTask { @InputFiles @@ -36,15 +36,19 @@ final generatePackageInfos = tasks.register('generatePackageInfos', GeneratePack it.files.from fileTree("src/main/java") } -spotless { - java { - endWithNewline() - indentWithSpaces() - removeUnusedImports() - toggleOffOn() - // Pin version to 4.31 because of a Spotless bug https://github.com/diffplug/spotless/issues/1992 - eclipse('4.31').configFile rootProject.file('codeformat/formatter-config.xml') - importOrder() +immaculate { + workflows.register('java') { + java() + trailingNewline() + noTabs() + googleFixImports() + toggleOff = 'spotless:off' + toggleOn = 'spotless:on' + eclipse { + version '3.37.0' + config = rootProject.file('codeformat/formatter-config.xml') + } + // courtesy of diffplug/spotless#240 // https://github.com/diffplug/spotless/issues/240#issuecomment-385206606 @@ -63,14 +67,13 @@ spotless { custom 'jetbrainsNullable', { String fileContents -> fileContents.replace('javax.annotation.Nullable', 'org.jetbrains.annotations.Nullable') } - bumpThisNumberIfACustomStepChanges(3) } } tasks.named('licenseFormat').configure { mustRunAfter generatePackageInfos } -tasks.named('spotlessApply').configure { +tasks.named('immaculateApply').configure { mustRunAfter generatePackageInfos mustRunAfter tasks.named('licenseFormat') } @@ -78,13 +81,13 @@ tasks.named('spotlessApply').configure { tasks.register('applyAllFormatting', Task) { dependsOn generatePackageInfos dependsOn tasks.named('licenseFormat') - dependsOn tasks.named('spotlessApply') + dependsOn tasks.named('immaculateApply') group = 'verification' } tasks.register('checkFormatting', Task) { dependsOn 'licenseCheck' - dependsOn 'spotlessCheck' + dependsOn 'immaculateCheck' group = 'verification' } diff --git a/coremods/build.gradle b/coremods/build.gradle index 127e7ec9dfc..dc92c1c7b84 100644 --- a/coremods/build.gradle +++ b/coremods/build.gradle @@ -1,6 +1,5 @@ plugins { id 'java-library' - id 'com.diffplug.spotless' id 'net.neoforged.licenser' id 'neoforge.formatting-conventions' } diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 41b36415464..f46b669df13 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -27,7 +27,7 @@ Contributing to NeoForge - If possible, write an automated test under the tests project. See [NEOGAMETESTS.md](NEOGAMETESTS.md) for more info. 10. Run `gradlew unpackSourcePatches` to generate patch-files from the patched sources 11. Run `gradlew applyAllFormatting` to automatically format sources -12. Check correct formatting with `gradlew spotlessCheck` +12. Check correct formatting with `gradlew checkFormatting` 13. Commit & Push 14. Make PR diff --git a/testframework/build.gradle b/testframework/build.gradle index d5d98b4059a..5b5a74316f7 100644 --- a/testframework/build.gradle +++ b/testframework/build.gradle @@ -1,7 +1,6 @@ plugins { id 'java' id 'maven-publish' - id 'com.diffplug.spotless' id 'net.neoforged.licenser' id 'neoforge.formatting-conventions' } diff --git a/tests/build.gradle b/tests/build.gradle index 37ea199d5bc..381884becdd 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -1,6 +1,5 @@ plugins { id 'java' - id 'com.diffplug.spotless' id 'net.neoforged.licenser' id 'neoforge.formatting-conventions' } From c05891287698d7119b17173f5d435888d24103f8 Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:48:13 +0100 Subject: [PATCH 07/13] Add immaculate rule that forbits @NotNull in patches (#1785) --- build.gradle | 12 ++++++++++++ .../resources/model/MultiPartBakedModel.java.patch | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 707385ed1a9..32f30a898cf 100644 --- a/build.gradle +++ b/build.gradle @@ -148,6 +148,18 @@ immaculate { return sb.toString() } + // Disallow explicit not null in patches, it's always implied. + custom 'noNotNull', { String fileContents -> + fileContents.eachLine { + if (!it.startsWith("+")) return + if (it.contains('@NotNull') || it.contains('@Nonnull') + || it.contains('@org.jetbrains.annotations.NotNull') + || it.contains('@javax.annotation.Nonnull')) { + throw new GradleException('@NotNull and @Nonnull are disallowed.') + } + } + } + //Replace any FQN versions of javax.annotation.Nullable with the jetbrains variant custom 'jetbrainsNullablePatches', { String fileContents -> fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable') diff --git a/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch b/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch index 8404abbec30..2150ecc135d 100644 --- a/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch +++ b/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch @@ -110,7 +110,7 @@ + } + + @Override // FORGE: Get render types based on the selectors matched by the given block state -+ public net.neoforged.neoforge.client.ChunkRenderTypeSet getRenderTypes(@org.jetbrains.annotations.NotNull BlockState state, @org.jetbrains.annotations.NotNull RandomSource rand, @org.jetbrains.annotations.NotNull net.neoforged.neoforge.client.model.data.ModelData data) { ++ public net.neoforged.neoforge.client.ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, net.neoforged.neoforge.client.model.data.ModelData data) { + var renderTypeSets = new java.util.LinkedList(); + var selectors = getSelectors(state); + for (int i = 0; i < selectors.length(); i++) From ce535a7c2dc0284f1a4f359b93163de6ba5a9a37 Mon Sep 17 00:00:00 2001 From: shartte Date: Thu, 26 Dec 2024 00:18:53 +0100 Subject: [PATCH 08/13] Fix the ability of the build script to use PR builds in installers (#1801) --- .../net/neoforged/neodev/NeoDevPlugin.java | 50 +++++++++++-------- .../neodev/installer/LibraryCollector.java | 18 +++++-- settings.gradle | 7 +++ 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java index 952d1686741..8b12aadd44d 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java @@ -30,6 +30,7 @@ import java.io.File; import java.net.URI; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -232,6 +233,7 @@ public void apply(Project project) { patchesFolder ); + var installerRepositoryUrls = getInstallerRepositoryUrls(project); // Launcher profile = the version.json file used by the Minecraft launcher. var createLauncherProfile = tasks.register("createLauncherProfile", CreateLauncherProfile.class, task -> { task.setGroup(INTERNAL_GROUP); @@ -240,17 +242,7 @@ public void apply(Project project) { task.getNeoForgeVersion().set(neoForgeVersion); task.getRawNeoFormVersion().set(rawNeoFormVersion); task.setLibraries(configurations.launcherProfileClasspath); - task.getRepositoryURLs().set(project.provider(() -> { - List repos = new ArrayList<>(); - for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) { - var uri = repo.getUrl(); - if (!uri.toString().endsWith("/")) { - uri = URI.create(uri + "/"); - } - repos.add(uri); - } - return repos; - })); + task.getRepositoryURLs().set(installerRepositoryUrls); // ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar. task.getIgnoreList().addAll("client-extra", "${version_name}.jar"); task.setModules(configurations.modulePath); @@ -269,17 +261,7 @@ public void apply(Project project) { task.addLibraries(configurations.launcherProfileClasspath); // We need the NeoForm zip for the SRG mappings. task.addLibraries(configurations.neoFormDataOnly); - task.getRepositoryURLs().set(project.provider(() -> { - List repos = new ArrayList<>(); - for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) { - var uri = repo.getUrl(); - if (!uri.toString().endsWith("/")) { - uri = URI.create(uri + "/"); - } - repos.add(uri); - } - return repos; - })); + task.getRepositoryURLs().set(installerRepositoryUrls); task.getUniversalJar().set(universalJar.flatMap(AbstractArchiveTask::getArchiveFile)); task.getInstallerProfile().set(neoDevBuildDir.map(dir -> dir.file("installer-profile.json"))); @@ -416,6 +398,30 @@ public void apply(Project project) { }); } + /** + * Get the list of Maven repositories that may contain artifacts for the installer. + */ + private static Provider> getInstallerRepositoryUrls(Project project) { + return project.provider(() -> { + List repos = new ArrayList<>(); + var projectRepos = project.getRepositories(); + if (!projectRepos.isEmpty()) { + for (var repo : projectRepos.withType(MavenArtifactRepository.class)) { + repos.add(repo.getUrl()); + } + } else { + // If no project repos are defined, use the repository list we exposed in settings.gradle via an extension + // See the end of settings.gradle for details + Collections.addAll(repos, (URI[]) project.getGradle().getExtensions().getByName("repositoryBaseUrls")); + } + + // Ensure all base urls end with a slash + repos.replaceAll(uri -> uri.toString().endsWith("/") ? uri : URI.create(uri + "/")); + + return repos; + }); + } + private static TaskProvider configureAccessTransformer( Project project, NeoDevConfigurations configurations, diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java index 7417ac14c33..9e7b3708732 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/LibraryCollector.java @@ -6,6 +6,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -21,6 +22,8 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.function.Function; @@ -41,7 +44,7 @@ public static List resolveLibraries(List repositoryUrls, Collectio throw new RuntimeException(e); } }).toList(); - LOGGER.info("Collected %d libraries".formatted(result.size())); + LOGGER.info("Collected {} libraries", result.size()); return result; } @@ -63,7 +66,9 @@ public static List resolveLibraries(List repositoryUrls, Collectio private final List> libraries = new ArrayList<>(); - private final HttpClient httpClient = HttpClient.newBuilder().build(); + private final HttpClient httpClient = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.NORMAL) + .build(); private LibraryCollector(List repoUrl) { this.repositoryUrls = new ArrayList<>(repoUrl); @@ -86,7 +91,7 @@ private LibraryCollector(List repoUrl) { LOGGER.info("Collecting libraries from:"); for (var repo : repositoryUrls) { - LOGGER.info(" - " + repo); + LOGGER.info(" - {}", repo); } } @@ -109,7 +114,7 @@ private void addLibrary(File file, MavenIdentifier identifier) throws IOExceptio return httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()) .thenApply(response -> { if (response.statusCode() != 200) { - LOGGER.info(" Got %d for %s".formatted(response.statusCode(), artifactUri)); + LOGGER.info(" Got {} for {}", response.statusCode(), artifactUri); String message = "Could not find %s: %d".formatted(artifactUri, response.statusCode()); // Prepend error message from previous repo if they all fail if (previousError != null) { @@ -117,7 +122,7 @@ private void addLibrary(File file, MavenIdentifier identifier) throws IOExceptio } throw new RuntimeException(message); } - LOGGER.info(" Found %s -> %s".formatted(name, artifactUri)); + LOGGER.info(" Found {} -> {}", name, artifactUri); return new Library( name, new LibraryDownload(new LibraryArtifact( @@ -132,6 +137,9 @@ private void addLibrary(File file, MavenIdentifier identifier) throws IOExceptio libraryFuture = makeRequest.apply(null); } else { libraryFuture = libraryFuture.exceptionallyCompose(error -> { + if (error instanceof CompletionException e) { + return makeRequest.apply(e.getCause().getMessage()); + } return makeRequest.apply(error.getMessage()); }); } diff --git a/settings.gradle b/settings.gradle index aff93fdd4ca..0efa2e7fedf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -43,3 +43,10 @@ include ':coremods' // Ensure a unique artifact id within JIJ that does not conflict with net.neoforged:coremods, which is // another external dependency. project(":coremods").name = "neoforge-coremods" + +// Expose the repository base URLs to projects to be able to access them +// See this Gradle issue for tracking a more permanent solution: +// https://github.com/gradle/gradle/issues/27260 +gradle.settingsEvaluated { + gradle.extensions.add("repositoryBaseUrls", dependencyResolutionManagement.repositories.findAll { it instanceof MavenArtifactRepository }.collect { it.url }.toArray(URI[]::new)) +} From e76d915e8d26527735c5b020ad9f9f55d7e55b58 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Thu, 2 Jan 2025 02:32:47 +0100 Subject: [PATCH 09/13] Revert "Add immaculate rule that forbits @NotNull in patches (#1785)" This reverts commit c05891287698d7119b17173f5d435888d24103f8. --- build.gradle | 12 ------------ .../resources/model/MultiPartBakedModel.java.patch | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 32f30a898cf..707385ed1a9 100644 --- a/build.gradle +++ b/build.gradle @@ -148,18 +148,6 @@ immaculate { return sb.toString() } - // Disallow explicit not null in patches, it's always implied. - custom 'noNotNull', { String fileContents -> - fileContents.eachLine { - if (!it.startsWith("+")) return - if (it.contains('@NotNull') || it.contains('@Nonnull') - || it.contains('@org.jetbrains.annotations.NotNull') - || it.contains('@javax.annotation.Nonnull')) { - throw new GradleException('@NotNull and @Nonnull are disallowed.') - } - } - } - //Replace any FQN versions of javax.annotation.Nullable with the jetbrains variant custom 'jetbrainsNullablePatches', { String fileContents -> fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable') diff --git a/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch b/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch index 2150ecc135d..8404abbec30 100644 --- a/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch +++ b/patches/net/minecraft/client/resources/model/MultiPartBakedModel.java.patch @@ -110,7 +110,7 @@ + } + + @Override // FORGE: Get render types based on the selectors matched by the given block state -+ public net.neoforged.neoforge.client.ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, net.neoforged.neoforge.client.model.data.ModelData data) { ++ public net.neoforged.neoforge.client.ChunkRenderTypeSet getRenderTypes(@org.jetbrains.annotations.NotNull BlockState state, @org.jetbrains.annotations.NotNull RandomSource rand, @org.jetbrains.annotations.NotNull net.neoforged.neoforge.client.model.data.ModelData data) { + var renderTypeSets = new java.util.LinkedList(); + var selectors = getSelectors(state); + for (int i = 0; i < selectors.length(); i++) From fcc790b93c629ec33218bd391c42aec2bf87d84f Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Wed, 1 Jan 2025 01:33:01 +0100 Subject: [PATCH 10/13] New FML Startup Experiments --- .../neoforge.formatting-conventions.gradle | 1 - .../neoforged/neodev/CreateUserDevConfig.java | 54 +++++++++---------- .../neodev/NeoDevConfigurations.java | 13 +++++ .../net/neoforged/neodev/NeoDevPlugin.java | 24 +++++---- .../neodev/installer/CreateArgsFile.java | 53 +++++++++++------- .../installer/CreateLauncherProfile.java | 36 +++++++++---- .../neodev/utils/DependencyUtils.java | 8 +-- gradle.properties | 5 +- projects/neoforge/build.gradle | 20 ++++--- server_files/args.txt | 18 +++---- settings.gradle | 9 ++++ .../neoforge/junit/JUnitBootstrapper.java | 21 ++++++++ .../neoforged/neoforge/junit/JUnitMain.java | 26 --------- ...eoforged.fml.startup.JUnitGameBootstrapper | 1 + 14 files changed, 165 insertions(+), 124 deletions(-) create mode 100644 src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java delete mode 100644 src/main/java/net/neoforged/neoforge/junit/JUnitMain.java create mode 100644 src/main/resources/META-INF/services/net.neoforged.fml.startup.JUnitGameBootstrapper diff --git a/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle b/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle index 0a26b947823..636b93be93c 100644 --- a/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle +++ b/buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle @@ -49,7 +49,6 @@ immaculate { config = rootProject.file('codeformat/formatter-config.xml') } - // courtesy of diffplug/spotless#240 // https://github.com/diffplug/spotless/issues/240#issuecomment-385206606 custom 'noWildcardImports', { String fileContents -> diff --git a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java index ab24c91d4d8..dc4c575f24a 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java @@ -53,6 +53,9 @@ public CreateUserDevConfig() {} @Input abstract ListProperty getModules(); + @Input + abstract ListProperty getJavaAgents(); + @Input abstract ListProperty getTestLibraries(); @@ -68,7 +71,7 @@ public CreateUserDevConfig() {} @TaskAction public void writeUserDevConfig() throws IOException { var config = new UserDevConfig( - 2, + 3, "net.neoforged:neoform:%s-%s@zip".formatted(getMinecraftVersion().get(), getRawNeoFormVersion().get()), "ats/", "joined.lzma", @@ -81,30 +84,27 @@ public void writeUserDevConfig() throws IOException { getLibraries().get(), getTestLibraries().get(), new LinkedHashMap<>(), - getModules().get()); + getModules().get(), + getJavaAgents().get() + ); for (var runType : RunType.values()) { - var launchTarget = switch (runType) { - case CLIENT -> "forgeclient"; - case DATA -> "forgedata"; - case GAME_TEST_SERVER, SERVER -> "forgeserver"; - case JUNIT -> "forgejunit"; - } + (getForNeoDev().get() ? "dev" : "userdev"); + var mainClass = switch (runType) { + case CLIENT -> "net.neoforged.fml.startup.Client"; + case DATA -> "net.neoforged.fml.startup.Data"; + case GAME_TEST_SERVER, SERVER -> "net.neoforged.fml.startup.Server"; + case JUNIT -> null; + }; List args = new ArrayList<>(); - Collections.addAll(args, - "--launchTarget", launchTarget); - if (runType == RunType.CLIENT || runType == RunType.JUNIT) { + if (runType == RunType.CLIENT) { // TODO: this is copied from NG but shouldn't it be the MC version? - Collections.addAll(args, - "--version", getNeoForgeVersion().get()); + Collections.addAll(args, "--version", getNeoForgeVersion().get()); } - if (runType == RunType.CLIENT || runType == RunType.DATA || runType == RunType.JUNIT) { - Collections.addAll(args, - "--assetIndex", "{asset_index}", - "--assetsDir", "{assets_root}"); + if (runType == RunType.CLIENT || runType == RunType.DATA) { + Collections.addAll(args, "--assetIndex", "{asset_index}", "--assetsDir", "{assets_root}"); } Collections.addAll(args, @@ -116,8 +116,6 @@ public void writeUserDevConfig() throws IOException { Map systemProperties = new LinkedHashMap<>(); systemProperties.put("java.net.preferIPv6Addresses", "system"); - systemProperties.put("ignoreList", String.join(",", getIgnoreList().get())); - systemProperties.put("legacyClassPath.file", "{minecraft_classpath_file}"); if (runType == RunType.CLIENT || runType == RunType.GAME_TEST_SERVER) { systemProperties.put("neoforge.enableGameTest", "true"); @@ -129,22 +127,19 @@ public void writeUserDevConfig() throws IOException { config.runs().put(runType.jsonName, new UserDevRunType( runType != RunType.JUNIT, - "cpw.mods.bootstraplauncher.BootstrapLauncher", + mainClass, args, List.of( - "-p", "{modules}", - "--add-modules", "ALL-MODULE-PATH", - "--add-opens", "java.base/java.util.jar=cpw.mods.securejarhandler", - "--add-opens", "java.base/java.lang.invoke=cpw.mods.securejarhandler", - "--add-exports", "java.base/sun.security.util=cpw.mods.securejarhandler", + "--add-opens", "java.base/java.util.jar=ALL-UNNAMED", + "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", + "--add-exports", "java.base/sun.security.util=ALL-UNNAMED", "--add-exports", "jdk.naming.dns/com.sun.jndi.dns=java.naming"), runType == RunType.CLIENT || runType == RunType.JUNIT, runType == RunType.GAME_TEST_SERVER || runType == RunType.SERVER, runType == RunType.DATA, runType == RunType.CLIENT || runType == RunType.GAME_TEST_SERVER, runType == RunType.JUNIT, - Map.of( - "MOD_CLASSES", "{source_roots}"), + Map.of("MOD_CLASSES", "{source_roots}"), systemProperties )); } @@ -183,7 +178,10 @@ record UserDevConfig( List libraries, List testLibraries, Map runs, - List modules) {} + List modules, + List javaAgents +) { +} record BinpatcherConfig( String version, diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java index 35eb5b570df..65223de8019 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevConfigurations.java @@ -44,6 +44,10 @@ static NeoDevConfigurations createAndSetup(Project project) { * (i.e. BootstrapLauncher and its dependencies). */ final Configuration moduleLibraries; + /** + * The Java Agents to attach to the running JVM when running the game. + */ + final Configuration javaAgents; /** * Libraries that should be accessible in mod development environments at compilation time only. * Currently, this is only used for MixinExtras, which is already available at runtime via JiJ in the NeoForge universal jar. @@ -73,6 +77,10 @@ static NeoDevConfigurations createAndSetup(Project project) { * Resolvable {@link #moduleLibraries}. */ final Configuration modulePath; + /** + * Resolvable {@link #javaAgents}. + */ + final Configuration javaAgentsClasspath; /** * Userdev dependencies (written to a json file in the userdev jar). * This should contain all of NeoForge's additional dependencies for userdev, @@ -125,12 +133,14 @@ private NeoDevConfigurations(Project project) { neoFormDependencies = dependencyScope(configurations, "neoFormDependencies"); libraries = dependencyScope(configurations, "libraries"); moduleLibraries = dependencyScope(configurations, "moduleLibraries"); + javaAgents = dependencyScope(configurations, "javaAgents"); userdevCompileOnly = dependencyScope(configurations, "userdevCompileOnly"); userdevTestFixtures = dependencyScope(configurations, "userdevTestFixtures"); neoFormDataOnly = resolvable(configurations, "neoFormDataOnly"); neoFormClasspath = resolvable(configurations, "neoFormClasspath"); modulePath = resolvable(configurations, "modulePath"); + javaAgentsClasspath = resolvable(configurations, "javaAgentsClasspath"); userdevClasspath = resolvable(configurations, "userdevClasspath"); userdevCompileOnlyClasspath = resolvable(configurations, "userdevCompileOnlyClasspath"); userdevTestClasspath = resolvable(configurations, "userdevTestClasspath"); @@ -152,6 +162,9 @@ private NeoDevConfigurations(Project project) { modulePath.extendsFrom(moduleLibraries); modulePath.shouldResolveConsistentlyWith(runtimeClasspath); + javaAgentsClasspath.extendsFrom(javaAgents); + javaAgentsClasspath.shouldResolveConsistentlyWith(runtimeClasspath); + userdevClasspath.extendsFrom(libraries, moduleLibraries, userdevCompileOnly); userdevClasspath.shouldResolveConsistentlyWith(runtimeClasspath); diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java index 8b12aadd44d..82944ed2b80 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java @@ -112,15 +112,15 @@ public void apply(Project project) { task.getRawNeoFormVersion().set(rawNeoFormVersion); task.getLibraries().addAll(DependencyUtils.configurationToGavList(configurations.userdevClasspath)); task.getModules().addAll(DependencyUtils.configurationToGavList(configurations.modulePath)); - task.getTestLibraries().addAll(DependencyUtils.configurationToGavList(configurations.userdevTestClasspath)); - task.getTestLibraries().add(neoForgeVersion.map(v -> "net.neoforged:testframework:" + v)); - task.getIgnoreList().addAll(configurations.userdevCompileOnlyClasspath.getIncoming().getArtifacts().getResolvedArtifacts().map(results -> { - return results.stream().map(r -> r.getFile().getName()).toList(); - })); - task.getIgnoreList().addAll("client-extra", "neoforge-"); - task.getBinpatcherGav().set(Tools.BINPATCHER.asGav(project)); - }); - } + task.getJavaAgents().addAll(DependencyUtils.configurationToGavList(configurations.javaAgentsClasspath)); + task.getTestLibraries().addAll(DependencyUtils.configurationToGavList(configurations.userdevTestClasspath)); + task.getTestLibraries().add(neoForgeVersion.map(v -> "net.neoforged:testframework:" + v)); + task.getIgnoreList().addAll(configurations.userdevCompileOnlyClasspath.getIncoming().getArtifacts().getResolvedArtifacts().map(results -> { + return results.stream().map(r -> r.getFile().getName()).toList(); + })); + task.getIgnoreList().addAll("client-extra", "neoforge-"); + task.getBinpatcherGav().set(Tools.BINPATCHER.asGav(project)); + });} // 2. Task to download assets. var downloadAssets = tasks.register("downloadAssets", DownloadAssets.class, task -> { @@ -246,6 +246,7 @@ public void apply(Project project) { // ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar. task.getIgnoreList().addAll("client-extra", "${version_name}.jar"); task.setModules(configurations.modulePath); + task.setJavaAgents(configurations.javaAgentsClasspath); task.getLauncherProfile().set(neoDevBuildDir.map(dir -> dir.file("launcher-profile.json"))); }); @@ -277,11 +278,11 @@ public void apply(Project project) { }); var createWindowsServerArgsFile = tasks.register("createWindowsServerArgsFile", CreateArgsFile.class, task -> { - task.setLibraries(";", configurations.launcherProfileClasspath, configurations.modulePath); + task.getPathSeparator().set(";"); task.getArgsFile().set(neoDevBuildDir.map(dir -> dir.file("windows-server-args.txt"))); }); var createUnixServerArgsFile = tasks.register("createUnixServerArgsFile", CreateArgsFile.class, task -> { - task.setLibraries(":", configurations.launcherProfileClasspath, configurations.modulePath); + task.getPathSeparator().set(":"); task.getArgsFile().set(neoDevBuildDir.map(dir -> dir.file("unix-server-args.txt"))); }); @@ -300,6 +301,7 @@ public void apply(Project project) { return results.stream().map(r -> r.getFile().getName()).toList(); })); task.getRawServerJar().set(createCleanArtifacts.flatMap(CreateCleanArtifacts::getRawServerJar)); + task.setLibraries(configurations.launcherProfileClasspath, configurations.modulePath, configurations.javaAgentsClasspath); }); } diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java index 6b403d5b944..23c9a59f236 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -44,21 +45,24 @@ public CreateArgsFile() {} public abstract Property getRawNeoFormVersion(); @Input - protected abstract Property getPathSeparator(); + public abstract Property getPathSeparator(); @Input - protected abstract Property getModules(); + protected abstract ListProperty getModules(); + + @Input + protected abstract ListProperty getJavaAgents(); @Input public abstract ListProperty getIgnoreList(); @Input - protected abstract Property getClasspath(); + protected abstract ListProperty getClasspath(); - public void setLibraries(String separator, Configuration classpath, Configuration modulePath) { - getPathSeparator().set(separator); - getClasspath().set(DependencyUtils.configurationToClasspath(classpath, "libraries/", separator)); - getModules().set(DependencyUtils.configurationToClasspath(modulePath, "libraries/", separator)); + public void setLibraries(Configuration classpath, Configuration modulePath, Configuration javaAgents) { + getClasspath().set(DependencyUtils.configurationToClasspathItems(classpath, "libraries/")); + getModules().set(DependencyUtils.configurationToClasspathItems(modulePath, "libraries/")); + getJavaAgents().set(DependencyUtils.configurationToClasspathItems(javaAgents, "libraries/")); } @InputFile @@ -71,13 +75,17 @@ public void setLibraries(String separator, Configuration classpath, Configuratio protected abstract ArchiveOperations getArchiveOperations(); private String resolveClasspath() throws IOException { - var ourClasspath = getClasspath().get() + getPathSeparator().get() - + "libraries/net/minecraft/server/%s/server-%s-extra.jar".formatted( - getRawNeoFormVersion().get(), getRawNeoFormVersion().get()); + String pathSeparator = getPathSeparator().get(); + var classpathItems = new ArrayList<>(getClasspath().get()); + classpathItems.add("libraries/net/minecraft/server/%s/server-%s-extra.jar".formatted( + getRawNeoFormVersion().get(), getRawNeoFormVersion().get())); + + // Remove any java agents, since they automatically are on the classpath + classpathItems.removeAll(getJavaAgents().get()); // The raw server jar also contains its own classpath. // We want to make sure that our versions of the libraries are used when there is a conflict. - var ourClasspathEntries = Stream.of(ourClasspath.split(getPathSeparator().get())) + var ourClasspathEntries = classpathItems.stream() .map(CreateArgsFile::stripVersionSuffix) .collect(Collectors.toSet()); @@ -89,9 +97,10 @@ private String resolveClasspath() throws IOException { .filter(path -> !ourClasspathEntries.contains(stripVersionSuffix(path))) // Exclude the actual MC server jar, which is under versions/ .filter(path -> path.startsWith("libraries/")) - .collect(Collectors.joining(getPathSeparator().get())); + .collect(Collectors.joining(pathSeparator)); - return ourClasspath + getPathSeparator().get() + filteredServerClasspath; + classpathItems.add(filteredServerClasspath); + return String.join(pathSeparator, classpathItems); } // Example: @@ -104,14 +113,18 @@ private static String stripVersionSuffix(String classpathEntry) { @TaskAction public void createArgsFile() throws IOException { + var pathSeparator = getPathSeparator().get(); + + var jvmOptions = new ArrayList(); + for (var javaAgent : getJavaAgents().get()) { + jvmOptions.add("-javaagent:" + javaAgent); + } + + jvmOptions.add("-cp"); + jvmOptions.add(resolveClasspath()); + var replacements = new HashMap(); - replacements.put("@MODULE_PATH@", getModules().get()); - replacements.put("@MODULES@", "ALL-MODULE-PATH"); - replacements.put("@IGNORE_LIST@", String.join(",", getIgnoreList().get())); - replacements.put("@PLUGIN_LAYER_LIBRARIES@", ""); - replacements.put("@GAME_LAYER_LIBRARIES@", ""); - replacements.put("@CLASS_PATH@", resolveClasspath()); - replacements.put("@TASK@", "forgeserver"); + replacements.put("@JVM_OPTIONS@", String.join("\n", jvmOptions)); replacements.put("@FORGE_VERSION@", getNeoForgeVersion().get()); replacements.put("@FML_VERSION@", getFmlVersion().get()); replacements.put("@MC_VERSION@", getMinecraftVersion().get()); diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java index 59681903043..830834cb43c 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java @@ -57,10 +57,17 @@ public void setLibraries(Configuration libraries) { public abstract ListProperty getIgnoreList(); @Input - protected abstract Property getModulePath(); + protected abstract ListProperty getModulePath(); + + @Input + protected abstract ListProperty getJavaAgentsClasspath(); public void setModules(Configuration modules) { - getModulePath().set(DependencyUtils.configurationToClasspath(modules, "${library_directory}/", "${classpath_separator}")); + getModulePath().set(DependencyUtils.configurationToClasspathItems(modules, "${library_directory}/")); + } + + public void setJavaAgents(Configuration javaAgents) { + getJavaAgentsClasspath().set(DependencyUtils.configurationToClasspathItems(javaAgents, "${library_directory}/")); } @OutputFile @@ -82,17 +89,26 @@ public void createLauncherProfile() throws IOException { var jvmArguments = new ArrayList<>(List.of( "-Djava.net.preferIPv6Addresses=system", - "-DignoreList=" + String.join(",", getIgnoreList().get()), "-DlibraryDirectory=${library_directory}")); + if (!getIgnoreList().get().isEmpty()) { + jvmArguments.add("-DignoreList=" + String.join(",", getIgnoreList().get())); + } + + var modulePath = getModulePath().get(); + if (!modulePath.isEmpty()) { + jvmArguments.add("-p"); + jvmArguments.add(String.join("${classpath_separator}", modulePath)); + } - jvmArguments.add("-p"); - jvmArguments.add(getModulePath().get()); + var javaAgents = getJavaAgentsClasspath().get(); + for (var javaAgent : javaAgents) { + jvmArguments.add("-javaagent:" + javaAgent); + } jvmArguments.addAll(List.of( - "--add-modules", "ALL-MODULE-PATH", - "--add-opens", "java.base/java.util.jar=cpw.mods.securejarhandler", - "--add-opens", "java.base/java.lang.invoke=cpw.mods.securejarhandler", - "--add-exports", "java.base/sun.security.util=cpw.mods.securejarhandler", + "--add-opens", "java.base/java.util.jar=ALL-UNNAMED", + "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", + "--add-exports", "java.base/sun.security.util=ALL-UNNAMED", "--add-exports", "jdk.naming.dns/com.sun.jndi.dns=java.naming")); var arguments = new LinkedHashMap>(); @@ -104,7 +120,7 @@ public void createLauncherProfile() throws IOException { time, time, "release", - "cpw.mods.bootstraplauncher.BootstrapLauncher", + "net.neoforged.fml.startup.Client", getMinecraftVersion().get(), arguments, libraries diff --git a/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java b/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java index ee1bb651754..cf2da917e32 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/utils/DependencyUtils.java @@ -68,17 +68,17 @@ public static Provider> configurationToGavList(Configuration config } /** - * Turns a configuration into a classpath string, + * Turns a configuration into a list of classpath items, * assuming that the contents of the configuration are installed following the Maven directory layout. * * @param prefix string to add in front of each classpath entry - * @param separator separator to add between each classpath entry */ - public static Provider configurationToClasspath(Configuration configuration, String prefix, String separator) { + public static Provider> configurationToClasspathItems(Configuration configuration, String prefix) { return configuration.getIncoming().getArtifacts().getResolvedArtifacts().map( results -> results.stream() .map(artifact -> prefix + guessMavenIdentifier(artifact).repositoryPath()) - .collect(Collectors.joining(separator)) + .distinct() + .toList() ); } } diff --git a/gradle.properties b/gradle.properties index f37ccd95425..cfad1c6b54c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,9 +32,6 @@ mergetool_version=2.0.0 accesstransformers_version=10.0.1 coremods_version=6.0.4 eventbus_version=8.0.2 -modlauncher_version=11.0.4 -securejarhandler_version=3.0.8 -bootstraplauncher_version=2.0.2 asm_version=9.7 mixin_version=0.15.2+mixin.0.8.7 terminalconsoleappender_version=1.3.0 @@ -43,7 +40,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.1 -fancy_mod_loader_version=4.0.34 +fancy_mod_loader_version=7.0.50-alpha-pr-232-startup-experiments-nomodules mojang_logging_version=1.1.1 log4j_version=2.22.1 guava_version=31.1.2-jre diff --git a/projects/neoforge/build.gradle b/projects/neoforge/build.gradle index 3912a5bd300..b8d436c5ec2 100644 --- a/projects/neoforge/build.gradle +++ b/projects/neoforge/build.gradle @@ -80,9 +80,8 @@ dependencies { endorseStrictVersions() } - moduleLibraries "cpw.mods:securejarhandler:${project.securejarhandler_version}" for (var asmModule : ["org.ow2.asm:asm", "org.ow2.asm:asm-commons", "org.ow2.asm:asm-tree", "org.ow2.asm:asm-util", "org.ow2.asm:asm-analysis"]) { - moduleLibraries(asmModule) { + libraries(asmModule) { // Vanilla ships with ASM 9.3 transitively (via their OpenID connect library dependency), we require // ASM in a more recent version and have to strictly require this to override the strict Minecraft version. version { @@ -90,8 +89,7 @@ dependencies { } } } - moduleLibraries "cpw.mods:bootstraplauncher:${project.bootstraplauncher_version}" - moduleLibraries "net.neoforged:JarJarFileSystems:${project.jarjar_version}" + libraries "net.neoforged:JarJarFileSystems:${project.jarjar_version}" libraries ("net.neoforged.fancymodloader:loader:${project.fancy_mod_loader_version}") { exclude group: 'org.slf4j' @@ -102,10 +100,12 @@ dependencies { exclude group: 'org.slf4j' exclude group: 'net.fabricmc' } + javaAgents ("net.neoforged.fancymodloader:loader:${project.fancy_mod_loader_version}") { + transitive = false + } libraries "net.neoforged:accesstransformers:${project.accesstransformers_version}" libraries "net.neoforged:bus:${project.eventbus_version}" libraries "net.neoforged:coremods:${project.coremods_version}" - libraries "cpw.mods:modlauncher:${project.modlauncher_version}" libraries "net.neoforged:mergetool:${project.mergetool_version}:api" libraries "com.electronwill.night-config:core:${project.nightconfig_version}" libraries "com.electronwill.night-config:toml:${project.nightconfig_version}" @@ -136,6 +136,11 @@ dependencies { implementation(jarJar(project(":neoforge-coremods"))) } +configurations.configureEach { + exclude(group: "cpw.mods", module: "modlauncher") + exclude(group: "cpw.mods", module: "securejarhandler") +} + neoDev { runs { configureEach { @@ -249,7 +254,7 @@ configurations { modDevApiElements { canBeDeclared = false canBeResolved = false - extendsFrom libraries, moduleLibraries, userdevCompileOnly, neoFormDependencies + extendsFrom libraries, userdevCompileOnly, neoFormDependencies attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -263,7 +268,7 @@ configurations { modDevRuntimeElements { canBeDeclared = false canBeResolved = false - extendsFrom libraries, moduleLibraries, neoFormDependencies + extendsFrom libraries, neoFormDependencies attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) @@ -277,7 +282,6 @@ configurations { modDevModulePath { canBeDeclared = false canBeResolved = false - extendsFrom moduleLibraries attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) diff --git a/server_files/args.txt b/server_files/args.txt index 2d72f2525cf..ad23ee1ffb8 100644 --- a/server_files/args.txt +++ b/server_files/args.txt @@ -1,18 +1,12 @@ --p @MODULE_PATH@ ---add-modules @MODULES@ ---add-opens java.base/java.util.jar=cpw.mods.securejarhandler ---add-opens java.base/java.lang.invoke=cpw.mods.securejarhandler ---add-exports java.base/sun.security.util=cpw.mods.securejarhandler +@JVM_OPTIONS@ +--add-opens java.base/java.util.jar=ALL-UNNAMED +--add-opens java.base/java.lang.invoke=ALL-UNNAMED +--add-exports java.base/sun.security.util=ALL-UNNAMED --add-exports jdk.naming.dns/com.sun.jndi.dns=java.naming -Djava.net.preferIPv6Addresses=system --DignoreList=@IGNORE_LIST@ --Dfml.pluginLayerLibraries=@PLUGIN_LAYER_LIBRARIES@ --Dfml.gameLayerLibraries=@GAME_LAYER_LIBRARIES@ -DlibraryDirectory=libraries --DlegacyClassPath=@CLASS_PATH@ -cpw.mods.bootstraplauncher.BootstrapLauncher ---launchTarget @TASK@ +net.neoforged.fml.startup.Server --fml.neoForgeVersion @FORGE_VERSION@ --fml.fmlVersion @FML_VERSION@ --fml.mcVersion @MC_VERSION@ ---fml.neoFormVersion @MCP_VERSION@ \ No newline at end of file +--fml.neoFormVersion @MCP_VERSION@ diff --git a/settings.gradle b/settings.gradle index 0efa2e7fedf..ecd46551758 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,15 @@ dependencyResolutionManagement { repositories { mavenCentral() mavenLocal() + maven { + name 'Maven for PR #232' // https://github.com/neoforged/FancyModLoader/pull/232 + url 'https://prmaven.neoforged.net/FancyModLoader/pr232' + content { + includeModule('net.neoforged.fancymodloader', 'junit-fml') + includeModule('net.neoforged.fancymodloader', 'loader') + includeModule('net.neoforged.fancymodloader', 'earlydisplay') + } + } } } diff --git a/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java b/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java new file mode 100644 index 00000000000..f94f7d937f2 --- /dev/null +++ b/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.neoforge.junit; + +import net.minecraft.SharedConstants; +import net.minecraft.server.Bootstrap; +import net.neoforged.fml.startup.JUnitGameBootstrapper; + +public class JUnitBootstrapper implements JUnitGameBootstrapper { + @Override + public void bootstrap() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + + // Load mods + net.neoforged.neoforge.server.loading.ServerModLoader.load(); + } +} diff --git a/src/main/java/net/neoforged/neoforge/junit/JUnitMain.java b/src/main/java/net/neoforged/neoforge/junit/JUnitMain.java deleted file mode 100644 index 99ce8c327b4..00000000000 --- a/src/main/java/net/neoforged/neoforge/junit/JUnitMain.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) NeoForged and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.neoforged.neoforge.junit; - -import cpw.mods.modlauncher.Launcher; -import net.minecraft.SharedConstants; -import net.minecraft.server.Bootstrap; -import net.neoforged.fml.common.asm.RuntimeDistCleaner; - -public class JUnitMain { - public static void main(String[] args) { - SharedConstants.tryDetectVersion(); - Bootstrap.bootStrap(); - - // Load mods - net.neoforged.neoforge.server.loading.ServerModLoader.load(); - - // We launch as a server, but we want client classes available. - // Passing null disables dist-cleaning. - var distCleaner = (RuntimeDistCleaner) Launcher.INSTANCE.environment().findLaunchPlugin("runtimedistcleaner").orElseThrow(); - distCleaner.setDistribution(null); - } -} diff --git a/src/main/resources/META-INF/services/net.neoforged.fml.startup.JUnitGameBootstrapper b/src/main/resources/META-INF/services/net.neoforged.fml.startup.JUnitGameBootstrapper new file mode 100644 index 00000000000..56783622a8a --- /dev/null +++ b/src/main/resources/META-INF/services/net.neoforged.fml.startup.JUnitGameBootstrapper @@ -0,0 +1 @@ +net.neoforged.neoforge.junit.JUnitBootstrapper \ No newline at end of file From 894e08d4f85e9952b65b926ba496777ce0010337 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Thu, 2 Jan 2025 12:28:41 +0100 Subject: [PATCH 11/13] Use spec version 2 to avoid having to update NFRT for now --- .../main/java/net/neoforged/neodev/CreateUserDevConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java index dc4c575f24a..b2e5e9baa60 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java @@ -71,7 +71,8 @@ public CreateUserDevConfig() {} @TaskAction public void writeUserDevConfig() throws IOException { var config = new UserDevConfig( - 3, + // TODO: Technically new field... backwards compatible? + 2, "net.neoforged:neoform:%s-%s@zip".formatted(getMinecraftVersion().get(), getRawNeoFormVersion().get()), "ats/", "joined.lzma", From 3693a41cefbca34b1ccc88ce4fe1a58e5332c744 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Fri, 3 Jan 2025 15:52:08 +0100 Subject: [PATCH 12/13] Bump FML --- gradle.properties | 2 +- .../java/net/neoforged/neoforge/junit/JUnitBootstrapper.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index cfad1c6b54c..99bae7d4aae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,7 +40,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.1 -fancy_mod_loader_version=7.0.50-alpha-pr-232-startup-experiments-nomodules +fancy_mod_loader_version=7.0.54-alpha-pr-232-startup-experiments-nomodules mojang_logging_version=1.1.1 log4j_version=2.22.1 guava_version=31.1.2-jre diff --git a/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java b/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java index f94f7d937f2..2ec6cb653e4 100644 --- a/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java +++ b/src/main/java/net/neoforged/neoforge/junit/JUnitBootstrapper.java @@ -7,11 +7,12 @@ import net.minecraft.SharedConstants; import net.minecraft.server.Bootstrap; +import net.neoforged.fml.loading.FMLLoader; import net.neoforged.fml.startup.JUnitGameBootstrapper; public class JUnitBootstrapper implements JUnitGameBootstrapper { @Override - public void bootstrap() { + public void bootstrap(FMLLoader loader) { SharedConstants.tryDetectVersion(); Bootstrap.bootStrap(); From 9df7f318c54aee8560c3d2fc7d890c44f765143c Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Fri, 3 Jan 2025 16:06:53 +0100 Subject: [PATCH 13/13] Bump FML --- .../java/net/neoforged/neodev/CreateUserDevConfig.java | 4 ---- .../src/main/java/net/neoforged/neodev/NeoDevPlugin.java | 4 ---- .../net/neoforged/neodev/installer/CreateArgsFile.java | 4 ---- .../neoforged/neodev/installer/CreateLauncherProfile.java | 8 ++------ server_files/args.txt | 1 - 5 files changed, 2 insertions(+), 19 deletions(-) diff --git a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java index b2e5e9baa60..78f77613473 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/CreateUserDevConfig.java @@ -35,9 +35,6 @@ public CreateUserDevConfig() {} @Input abstract Property getForNeoDev(); - @Input - abstract Property getFmlVersion(); - @Input abstract Property getMinecraftVersion(); @@ -110,7 +107,6 @@ public void writeUserDevConfig() throws IOException { Collections.addAll(args, "--gameDir", ".", - "--fml.fmlVersion", getFmlVersion().get(), "--fml.mcVersion", getMinecraftVersion().get(), "--fml.neoForgeVersion", getNeoForgeVersion().get(), "--fml.neoFormVersion", getRawNeoFormVersion().get()); diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java index 82944ed2b80..5729bdb7a61 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java @@ -47,7 +47,6 @@ public void apply(Project project) { var neoDevBuildDir = project.getLayout().getBuildDirectory().dir("neodev"); var rawNeoFormVersion = project.getProviders().gradleProperty("neoform_version"); - var fmlVersion = project.getProviders().gradleProperty("fancy_mod_loader_version"); var minecraftVersion = project.getProviders().gradleProperty("minecraft_version"); var neoForgeVersion = project.provider(() -> project.getVersion().toString()); var mcAndNeoFormVersion = minecraftVersion.zip(rawNeoFormVersion, (mc, nf) -> mc + "-" + nf); @@ -106,7 +105,6 @@ public void apply(Project project) { for (var taskProvider : List.of(writeNeoDevConfig, writeUserDevConfig)) { taskProvider.configure(task -> { task.setGroup(INTERNAL_GROUP); - task.getFmlVersion().set(fmlVersion); task.getMinecraftVersion().set(minecraftVersion); task.getNeoForgeVersion().set(neoForgeVersion); task.getRawNeoFormVersion().set(rawNeoFormVersion); @@ -237,7 +235,6 @@ public void apply(Project project) { // Launcher profile = the version.json file used by the Minecraft launcher. var createLauncherProfile = tasks.register("createLauncherProfile", CreateLauncherProfile.class, task -> { task.setGroup(INTERNAL_GROUP); - task.getFmlVersion().set(fmlVersion); task.getMinecraftVersion().set(minecraftVersion); task.getNeoForgeVersion().set(neoForgeVersion); task.getRawNeoFormVersion().set(rawNeoFormVersion); @@ -290,7 +287,6 @@ public void apply(Project project) { taskProvider.configure(task -> { task.setGroup(INTERNAL_GROUP); task.getTemplate().set(project.getRootProject().file("server_files/args.txt")); - task.getFmlVersion().set(fmlVersion); task.getMinecraftVersion().set(minecraftVersion); task.getNeoForgeVersion().set(neoForgeVersion); task.getRawNeoFormVersion().set(rawNeoFormVersion); diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java index 23c9a59f236..199003560e9 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateArgsFile.java @@ -32,9 +32,6 @@ public CreateArgsFile() {} @InputFile public abstract RegularFileProperty getTemplate(); - @Input - public abstract Property getFmlVersion(); - @Input public abstract Property getMinecraftVersion(); @@ -126,7 +123,6 @@ public void createArgsFile() throws IOException { var replacements = new HashMap(); replacements.put("@JVM_OPTIONS@", String.join("\n", jvmOptions)); replacements.put("@FORGE_VERSION@", getNeoForgeVersion().get()); - replacements.put("@FML_VERSION@", getFmlVersion().get()); replacements.put("@MC_VERSION@", getMinecraftVersion().get()); replacements.put("@MCP_VERSION@", getRawNeoFormVersion().get()); diff --git a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java index 830834cb43c..a579d644e72 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java @@ -31,9 +31,6 @@ public abstract class CreateLauncherProfile extends DefaultTask { @Inject public CreateLauncherProfile() {} - @Input - public abstract Property getFmlVersion(); - @Input public abstract Property getMinecraftVersion(); @@ -82,10 +79,9 @@ public void createLauncherProfile() throws IOException { var gameArguments = new ArrayList<>(List.of( "--fml.neoForgeVersion", getNeoForgeVersion().get(), - "--fml.fmlVersion", getFmlVersion().get(), "--fml.mcVersion", getMinecraftVersion().get(), - "--fml.neoFormVersion", getRawNeoFormVersion().get(), - "--launchTarget", "forgeclient")); + "--fml.neoFormVersion", getRawNeoFormVersion().get() + )); var jvmArguments = new ArrayList<>(List.of( "-Djava.net.preferIPv6Addresses=system", diff --git a/server_files/args.txt b/server_files/args.txt index ad23ee1ffb8..40878da0b9f 100644 --- a/server_files/args.txt +++ b/server_files/args.txt @@ -7,6 +7,5 @@ -DlibraryDirectory=libraries net.neoforged.fml.startup.Server --fml.neoForgeVersion @FORGE_VERSION@ ---fml.fmlVersion @FML_VERSION@ --fml.mcVersion @MC_VERSION@ --fml.neoFormVersion @MCP_VERSION@