From 5098f02d9e5cee178f37a4db7df7f391782269ae Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Sat, 31 Aug 2024 18:07:41 +0200 Subject: [PATCH 1/3] Remove dependency and extendsFrom from ModModel DSL --- BREAKING_CHANGES.md | 3 ++ .../moddevgradle/dsl/InternalModelHelper.java | 4 --- .../neoforged/moddevgradle/dsl/ModModel.java | 35 ------------------- .../moddevgradle/internal/RunUtils.java | 1 - testproject/build.gradle | 4 ++- .../src/main/resources/META-INF/MANIFEST.MF | 1 + testproject/jijtest/build.gradle | 6 +++- 7 files changed, 12 insertions(+), 42 deletions(-) create mode 100644 testproject/coremod/src/main/resources/META-INF/MANIFEST.MF diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 1f2b9147..e61de41d 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -15,3 +15,6 @@ Nonetheless, every single breaking change is documented here, along with a sugge - This is meant to catch usage mistakes. - Run `beforeTask`s do not run on IDE project sync anymore. - To run a task on sync, use `neoForge.ideSyncTask `. +- Removal of `dependency` and `extendsFrom` inside the `neoForge.mods {}` block. + - These functions generally do not work, and were removed to reduce confusion. + - `sourceSet ` should be used instead. If this is not sufficient, please open an issue. diff --git a/src/main/java/net/neoforged/moddevgradle/dsl/InternalModelHelper.java b/src/main/java/net/neoforged/moddevgradle/dsl/InternalModelHelper.java index 30ac9c1a..1650b2c9 100644 --- a/src/main/java/net/neoforged/moddevgradle/dsl/InternalModelHelper.java +++ b/src/main/java/net/neoforged/moddevgradle/dsl/InternalModelHelper.java @@ -13,10 +13,6 @@ public class InternalModelHelper { public InternalModelHelper() { } - public static Configuration getModConfiguration(ModModel modModel) { - return modModel.getConfiguration(); - } - public static String nameOfRun(RunModel run, @Nullable String prefix, @Nullable String suffix) { return StringUtils.uncapitalize((prefix == null ? "" : prefix) + StringUtils.capitalize(run.getName()) diff --git a/src/main/java/net/neoforged/moddevgradle/dsl/ModModel.java b/src/main/java/net/neoforged/moddevgradle/dsl/ModModel.java index 9c455696..02368b4d 100644 --- a/src/main/java/net/neoforged/moddevgradle/dsl/ModModel.java +++ b/src/main/java/net/neoforged/moddevgradle/dsl/ModModel.java @@ -1,13 +1,8 @@ package net.neoforged.moddevgradle.dsl; -import net.neoforged.moddevgradle.internal.utils.StringUtils; import org.gradle.api.Named; -import org.gradle.api.Project; -import org.gradle.api.artifacts.Configuration; import org.gradle.api.provider.ListProperty; -import org.gradle.api.provider.Property; import org.gradle.api.tasks.SourceSet; -import org.gradle.api.tasks.SourceSetContainer; import javax.inject.Inject; import java.util.List; @@ -16,12 +11,6 @@ * Model of a mod. This tells the moddev plugin which classes and resources need to be combined to produce a valid mod. */ public abstract class ModModel implements Named { - /** - * Created on-demand if the user wants to add content to this mod using cross-project references - * or just standard dependency notation. - */ - private Configuration configuration; - @Inject public ModModel() { // TODO: We could potentially do a bit of name validation @@ -29,35 +18,11 @@ public ModModel() { getModSourceSets().finalizeValueOnRead(); } - @Inject - protected abstract Project getProject(); - @Override public abstract String getName(); - Configuration getConfiguration() { - if (configuration == null) { - configuration = getProject().getConfigurations().create("neoForgeModContent" + StringUtils.capitalize(getName()), configuration -> { - configuration.setCanBeConsumed(false); - configuration.setCanBeResolved(true); - }); - } - return configuration; - } - // Do not name getSourceSets or it will conflict with project.sourceSets in scripts. public abstract ListProperty getModSourceSets(); - public void dependency(CharSequence dependencyNotation) { - getConfiguration().getDependencies().add(getProject().getDependencyFactory().create(dependencyNotation)); - } - - public void dependency(Project projectRef) { - getConfiguration().getDependencies().add(getProject().getDependencyFactory().create(projectRef)); - } - - public void extendsFrom(Configuration configuration) { - getConfiguration().extendsFrom(configuration); - } public void sourceSet(SourceSet sourceSet) { getModSourceSets().add(sourceSet); diff --git a/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java b/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java index a23efb28..7b874642 100644 --- a/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java +++ b/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java @@ -294,7 +294,6 @@ private static Provider> buildModFolders(Project project, return modsProvider.zip(testedModProvider, ((mods, testedMod) -> mods.stream() .collect(Collectors.toMap(ModModel::getName, mod -> { var modFolder = project.getObjects().newInstance(ModFolder.class); - modFolder.getFolders().from(InternalModelHelper.getModConfiguration(mod)); var sourceSets = mod.getModSourceSets().get(); diff --git a/testproject/build.gradle b/testproject/build.gradle index 6c904503..51a3051e 100644 --- a/testproject/build.gradle +++ b/testproject/build.gradle @@ -2,6 +2,8 @@ plugins { id 'net.neoforged.moddev' } +evaluationDependsOn(":subproject") // Because of the sourceset reference + sourceSets { api } @@ -52,7 +54,7 @@ neoForge { testproject { sourceSet sourceSets.main sourceSet sourceSets.api - dependency project(":subproject") + sourceSet project(":subproject").sourceSets.main } } diff --git a/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF b/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..5e57fdd4 --- /dev/null +++ b/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1 @@ +FMLModType: LIBRARY diff --git a/testproject/jijtest/build.gradle b/testproject/jijtest/build.gradle index 76f457d9..e89a1bbd 100644 --- a/testproject/jijtest/build.gradle +++ b/testproject/jijtest/build.gradle @@ -2,7 +2,11 @@ plugins { id 'net.neoforged.moddev' } +evaluationDependsOn(":coremod") // Because of the sourceset reference + dependencies { + implementation project(":coremod") + testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' jarJar(project(":coremod")) @@ -33,7 +37,7 @@ neoForge { sourceSet sourceSets.main } coremod { - dependency project(":coremod") + sourceSet project(":coremod").sourceSets.main } } From 96f2624104a29f644c2cbc5353c16c8592035a9b Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Sun, 1 Sep 2024 22:51:49 +0200 Subject: [PATCH 2/3] Throw on duplicate source sets in mods --- BREAKING_CHANGES.md | 2 ++ .../java/net/neoforged/moddevgradle/internal/RunUtils.java | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index e61de41d..01937936 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -18,3 +18,5 @@ Nonetheless, every single breaking change is documented here, along with a sugge - Removal of `dependency` and `extendsFrom` inside the `neoForge.mods {}` block. - These functions generally do not work, and were removed to reduce confusion. - `sourceSet ` should be used instead. If this is not sufficient, please open an issue. +- `mods` cannot contain the same source set multiple times. + - This is meant to catch usage mistakes. diff --git a/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java b/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java index 7b874642..b86cac73 100644 --- a/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java +++ b/src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java @@ -9,6 +9,7 @@ import net.neoforged.moddevgradle.internal.utils.IdeDetection; import net.neoforged.moddevgradle.internal.utils.OperatingSystem; import org.gradle.api.GradleException; +import org.gradle.api.InvalidUserCodeException; import org.gradle.api.Project; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.Directory; @@ -297,7 +298,11 @@ private static Provider> buildModFolders(Project project, var sourceSets = mod.getModSourceSets().get(); - for (var sourceSet : sourceSets) { + for (int i = 0; i < sourceSets.size(); ++i) { + var sourceSet = sourceSets.get(i); + if (sourceSets.subList(0, i).contains(sourceSet)) { + throw new InvalidUserCodeException("Duplicate source set '%s' in mod '%s'".formatted(sourceSet.getName(), mod.getName())); + } outputFolderResolver.accept(sourceSet, modFolder.getFolders()); } From 17e2703ca7225349e21d46bd4f13366266e7c03d Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Sun, 1 Sep 2024 23:09:46 +0200 Subject: [PATCH 3/3] Add Automatic-Module-Name to fix coremod module name in jijtest --- testproject/coremod/build.gradle | 3 ++- testproject/coremod/src/main/resources/META-INF/MANIFEST.MF | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/testproject/coremod/build.gradle b/testproject/coremod/build.gradle index 37fbfda4..379c8eda 100644 --- a/testproject/coremod/build.gradle +++ b/testproject/coremod/build.gradle @@ -11,7 +11,8 @@ java { jar { manifest { attributes([ - "FMLModType": "LIBRARY" + "FMLModType": "LIBRARY", + "Automatic-Module-Name": "testproject.coremod" ]) } } diff --git a/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF b/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF index 5e57fdd4..dd206f1e 100644 --- a/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF +++ b/testproject/coremod/src/main/resources/META-INF/MANIFEST.MF @@ -1 +1,2 @@ FMLModType: LIBRARY +Automatic-Module-Name: testproject.coremod