Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency and extendsFrom from ModModel DSL #150

Merged
merged 3 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ 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 <task>`.
- Removal of `dependency` and `extendsFrom` inside the `neoForge.mods {}` block.
- These functions generally do not work, and were removed to reduce confusion.
- `sourceSet <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.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/net/neoforged/moddevgradle/dsl/ModModel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,48 +11,18 @@
* 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
getModSourceSets().convention(List.of());
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<SourceSet> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -294,11 +295,14 @@ private static Provider<Map<String, ModFolder>> 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();

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());
}

Expand Down
4 changes: 3 additions & 1 deletion testproject/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'net.neoforged.moddev'
}

evaluationDependsOn(":subproject") // Because of the sourceset reference

sourceSets {
api
}
Expand Down Expand Up @@ -52,7 +54,7 @@ neoForge {
testproject {
sourceSet sourceSets.main
sourceSet sourceSets.api
dependency project(":subproject")
sourceSet project(":subproject").sourceSets.main
}
}

Expand Down
3 changes: 2 additions & 1 deletion testproject/coremod/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ java {
jar {
manifest {
attributes([
"FMLModType": "LIBRARY"
"FMLModType": "LIBRARY",
"Automatic-Module-Name": "testproject.coremod"
])
}
}
Expand Down
2 changes: 2 additions & 0 deletions testproject/coremod/src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FMLModType: LIBRARY
Automatic-Module-Name: testproject.coremod
6 changes: 5 additions & 1 deletion testproject/jijtest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -33,7 +37,7 @@ neoForge {
sourceSet sourceSets.main
}
coremod {
dependency project(":coremod")
sourceSet project(":coremod").sourceSets.main
}
}

Expand Down
Loading