Skip to content

Commit 5bf2286

Browse files
authored
Remove dependency and extendsFrom from ModModel DSL (#150)
1 parent 3bae0a3 commit 5bf2286

File tree

8 files changed

+23
-44
lines changed

8 files changed

+23
-44
lines changed

BREAKING_CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ Nonetheless, every single breaking change is documented here, along with a sugge
1515
- This is meant to catch usage mistakes.
1616
- Run `beforeTask`s do not run on IDE project sync anymore.
1717
- To run a task on sync, use `neoForge.ideSyncTask <task>`.
18+
- Removal of `dependency` and `extendsFrom` inside the `neoForge.mods {}` block.
19+
- These functions generally do not work, and were removed to reduce confusion.
20+
- `sourceSet <sourceSet>` should be used instead. If this is not sufficient, please open an issue.
21+
- `mods` cannot contain the same source set multiple times.
22+
- This is meant to catch usage mistakes.

src/main/java/net/neoforged/moddevgradle/dsl/InternalModelHelper.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ public class InternalModelHelper {
1313
public InternalModelHelper() {
1414
}
1515

16-
public static Configuration getModConfiguration(ModModel modModel) {
17-
return modModel.getConfiguration();
18-
}
19-
2016
public static String nameOfRun(RunModel run, @Nullable String prefix, @Nullable String suffix) {
2117
return StringUtils.uncapitalize((prefix == null ? "" : prefix)
2218
+ StringUtils.capitalize(run.getName())

src/main/java/net/neoforged/moddevgradle/dsl/ModModel.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package net.neoforged.moddevgradle.dsl;
22

3-
import net.neoforged.moddevgradle.internal.utils.StringUtils;
43
import org.gradle.api.Named;
5-
import org.gradle.api.Project;
6-
import org.gradle.api.artifacts.Configuration;
74
import org.gradle.api.provider.ListProperty;
8-
import org.gradle.api.provider.Property;
95
import org.gradle.api.tasks.SourceSet;
10-
import org.gradle.api.tasks.SourceSetContainer;
116

127
import javax.inject.Inject;
138
import java.util.List;
@@ -16,48 +11,18 @@
1611
* Model of a mod. This tells the moddev plugin which classes and resources need to be combined to produce a valid mod.
1712
*/
1813
public abstract class ModModel implements Named {
19-
/**
20-
* Created on-demand if the user wants to add content to this mod using cross-project references
21-
* or just standard dependency notation.
22-
*/
23-
private Configuration configuration;
24-
2514
@Inject
2615
public ModModel() {
2716
// TODO: We could potentially do a bit of name validation
2817
getModSourceSets().convention(List.of());
2918
getModSourceSets().finalizeValueOnRead();
3019
}
3120

32-
@Inject
33-
protected abstract Project getProject();
34-
3521
@Override
3622
public abstract String getName();
3723

38-
Configuration getConfiguration() {
39-
if (configuration == null) {
40-
configuration = getProject().getConfigurations().create("neoForgeModContent" + StringUtils.capitalize(getName()), configuration -> {
41-
configuration.setCanBeConsumed(false);
42-
configuration.setCanBeResolved(true);
43-
});
44-
}
45-
return configuration;
46-
}
47-
4824
// Do not name getSourceSets or it will conflict with project.sourceSets in scripts.
4925
public abstract ListProperty<SourceSet> getModSourceSets();
50-
public void dependency(CharSequence dependencyNotation) {
51-
getConfiguration().getDependencies().add(getProject().getDependencyFactory().create(dependencyNotation));
52-
}
53-
54-
public void dependency(Project projectRef) {
55-
getConfiguration().getDependencies().add(getProject().getDependencyFactory().create(projectRef));
56-
}
57-
58-
public void extendsFrom(Configuration configuration) {
59-
getConfiguration().extendsFrom(configuration);
60-
}
6126

6227
public void sourceSet(SourceSet sourceSet) {
6328
getModSourceSets().add(sourceSet);

src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.neoforged.moddevgradle.internal.utils.IdeDetection;
1010
import net.neoforged.moddevgradle.internal.utils.OperatingSystem;
1111
import org.gradle.api.GradleException;
12+
import org.gradle.api.InvalidUserCodeException;
1213
import org.gradle.api.Project;
1314
import org.gradle.api.file.ConfigurableFileCollection;
1415
import org.gradle.api.file.Directory;
@@ -294,11 +295,14 @@ private static Provider<Map<String, ModFolder>> buildModFolders(Project project,
294295
return modsProvider.zip(testedModProvider, ((mods, testedMod) -> mods.stream()
295296
.collect(Collectors.toMap(ModModel::getName, mod -> {
296297
var modFolder = project.getObjects().newInstance(ModFolder.class);
297-
modFolder.getFolders().from(InternalModelHelper.getModConfiguration(mod));
298298

299299
var sourceSets = mod.getModSourceSets().get();
300300

301-
for (var sourceSet : sourceSets) {
301+
for (int i = 0; i < sourceSets.size(); ++i) {
302+
var sourceSet = sourceSets.get(i);
303+
if (sourceSets.subList(0, i).contains(sourceSet)) {
304+
throw new InvalidUserCodeException("Duplicate source set '%s' in mod '%s'".formatted(sourceSet.getName(), mod.getName()));
305+
}
302306
outputFolderResolver.accept(sourceSet, modFolder.getFolders());
303307
}
304308

testproject/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ plugins {
22
id 'net.neoforged.moddev'
33
}
44

5+
evaluationDependsOn(":subproject") // Because of the sourceset reference
6+
57
sourceSets {
68
api
79
}
@@ -52,7 +54,7 @@ neoForge {
5254
testproject {
5355
sourceSet sourceSets.main
5456
sourceSet sourceSets.api
55-
dependency project(":subproject")
57+
sourceSet project(":subproject").sourceSets.main
5658
}
5759
}
5860

testproject/coremod/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ java {
1111
jar {
1212
manifest {
1313
attributes([
14-
"FMLModType": "LIBRARY"
14+
"FMLModType": "LIBRARY",
15+
"Automatic-Module-Name": "testproject.coremod"
1516
])
1617
}
1718
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FMLModType: LIBRARY
2+
Automatic-Module-Name: testproject.coremod

testproject/jijtest/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ plugins {
22
id 'net.neoforged.moddev'
33
}
44

5+
evaluationDependsOn(":coremod") // Because of the sourceset reference
6+
57
dependencies {
8+
implementation project(":coremod")
9+
610
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
711
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
812
jarJar(project(":coremod"))
@@ -33,7 +37,7 @@ neoForge {
3337
sourceSet sourceSets.main
3438
}
3539
coremod {
36-
dependency project(":coremod")
40+
sourceSet project(":coremod").sourceSets.main
3741
}
3842
}
3943

0 commit comments

Comments
 (0)