From 22a4a11360d411e0d7edfefb2c6d955fb2583000 Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Fri, 28 Jun 2024 20:14:00 +0300 Subject: [PATCH] Add an option (false by default) to validate ATs (#64) --- README.md | 8 ++++++-- .../net/neoforged/moddevgradle/dsl/NeoForgeExtension.java | 8 ++++++++ .../net/neoforged/moddevgradle/dsl/NeoFormRuntime.java | 3 +-- .../internal/CreateMinecraftArtifactsTask.java | 8 ++++++++ .../net/neoforged/moddevgradle/internal/ModDevPlugin.java | 1 + testproject/gradle.properties | 2 +- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c3241173..45362a55 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,11 @@ plugins { neoForge { // We currently only support NeoForge versions later than 21.0.x // See https://projects.neoforged.net/neoforged/neoforge for the latest updates - version = "21.0.0-beta" + version = "21.0.42-beta" + + // Validate AT files and raise errors when they have invalid targets + // This option is false by default, but turning it on is recommended + validateAccessTransformers = true runs { client { @@ -377,7 +381,7 @@ configurations.all { ```groovy neoForge { neoFormRuntime { - // Use specific NFRT version + // Use a specific NFRT version // Gradle Property: neoForge.neoFormRuntime.version version = "1.2.3" diff --git a/src/main/java/net/neoforged/moddevgradle/dsl/NeoForgeExtension.java b/src/main/java/net/neoforged/moddevgradle/dsl/NeoForgeExtension.java index e9d2b0cb..f8eb0f0b 100644 --- a/src/main/java/net/neoforged/moddevgradle/dsl/NeoForgeExtension.java +++ b/src/main/java/net/neoforged/moddevgradle/dsl/NeoForgeExtension.java @@ -48,6 +48,7 @@ public NeoForgeExtension(Project project) { return List.of(); })); + getValidateAccessTransformers().convention(false); } /** @@ -91,6 +92,13 @@ public void addModdingDependenciesTo(SourceSet sourceSet) { */ public abstract ListProperty getAccessTransformers(); + /** + * Enable access transformer validation, raising fatal errors if an AT targets a member that doesn't exist. + *

+ * Default {@code false}
+ */ + public abstract Property getValidateAccessTransformers(); + public NamedDomainObjectContainer getMods() { return mods; } diff --git a/src/main/java/net/neoforged/moddevgradle/dsl/NeoFormRuntime.java b/src/main/java/net/neoforged/moddevgradle/dsl/NeoFormRuntime.java index 4384a8d1..c8e90721 100644 --- a/src/main/java/net/neoforged/moddevgradle/dsl/NeoFormRuntime.java +++ b/src/main/java/net/neoforged/moddevgradle/dsl/NeoFormRuntime.java @@ -11,7 +11,7 @@ * the Minecraft artifacts for compiling and mods. */ public abstract class NeoFormRuntime { - private static final String DEFAULT_NFRT_VERSION = "0.1.58"; + private static final String DEFAULT_NFRT_VERSION = "0.1.63"; @Inject public NeoFormRuntime(Project project) { @@ -65,5 +65,4 @@ public NeoFormRuntime(Project project) { * Gradle property: {@code neoForge.neoFormRuntime.analyzeCacheMisses}. */ public abstract Property getAnalyzeCacheMisses(); - } diff --git a/src/main/java/net/neoforged/moddevgradle/internal/CreateMinecraftArtifactsTask.java b/src/main/java/net/neoforged/moddevgradle/internal/CreateMinecraftArtifactsTask.java index 07d9065c..3af610a9 100644 --- a/src/main/java/net/neoforged/moddevgradle/internal/CreateMinecraftArtifactsTask.java +++ b/src/main/java/net/neoforged/moddevgradle/internal/CreateMinecraftArtifactsTask.java @@ -6,6 +6,7 @@ import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import org.gradle.work.DisableCachingByDefault; @@ -27,6 +28,10 @@ public CreateMinecraftArtifactsTask() { @InputFiles abstract ConfigurableFileCollection getAccessTransformers(); + @Input + @Optional + abstract Property getValidateAccessTransformers(); + @Input abstract Property getParchmentEnabled(); @@ -61,6 +66,9 @@ public void createArtifacts() { args.add("--access-transformer"); args.add(accessTransformer.getAbsolutePath()); } + if (getValidateAccessTransformers().getOrElse(false)) { + args.add("--validate-access-transformers"); + } if (getParchmentEnabled().get()) { var parchmentData = getParchmentData().getFiles(); diff --git a/src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java b/src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java index 089ad8c6..532cf3ed 100644 --- a/src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java +++ b/src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java @@ -204,6 +204,7 @@ public void apply(Project project) { task.setDescription("Creates the NeoForge and Minecraft artifacts by invoking NFRT."); task.getAccessTransformers().from(accessTransformers); + task.getValidateAccessTransformers().set(extension.getValidateAccessTransformers()); task.getParchmentData().from(parchmentData); task.getParchmentEnabled().set(parchment.getEnabled()); task.getParchmentConflictResolutionPrefix().set(parchment.getConflictResolutionPrefix()); diff --git a/testproject/gradle.properties b/testproject/gradle.properties index 3dc69b91..307b9c9b 100644 --- a/testproject/gradle.properties +++ b/testproject/gradle.properties @@ -1,5 +1,5 @@ org.gradle.configuration-cache=true # Dependency versions -neoforge_version=21.0.37-beta +neoforge_version=21.0.42-beta