Skip to content

Commit

Permalink
Use the same userdev config for userdev and neodev (#1698)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Nov 26, 2024
1 parent bc0cdb7 commit 3ddaffa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ abstract class CreateUserDevConfig extends DefaultTask {
@Inject
public CreateUserDevConfig() {}

/**
* Toggles the launch type written to the userdev configuration between *dev and *userdev.
*/
@Input
abstract Property<Boolean> getForNeoDev();

@Input
abstract Property<String> getFmlVersion();

Expand Down Expand Up @@ -85,11 +79,11 @@ public void writeUserDevConfig() throws IOException {

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");
case CLIENT -> "forgeclientdev";
case DATA -> "forgedatadev";
case GAME_TEST_SERVER, SERVER -> "forgeserverdev";
case JUNIT -> "forgejunitdev";
};

List<String> args = new ArrayList<>();
Collections.addAll(args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand Down Expand Up @@ -33,7 +32,10 @@ public void apply(Project project) {

// TODO: this is temporary
var downloadAssets = neoForgeProject.getTasks().named("downloadAssets", DownloadAssets.class);
var writeNeoDevConfig = neoForgeProject.getTasks().named("writeNeoDevConfig", CreateUserDevConfig.class);

var neoForgeConfigOnly = project.getConfigurations().create("neoForgeConfigOnly", spec -> {
spec.getDependencies().add(projectDep(dependencyFactory, neoForgeProject, "net.neoforged:neoforge-moddev-config"));
});

Consumer<Configuration> configureLegacyClasspath = spec -> {
spec.getDependencies().add(projectDep(dependencyFactory, neoForgeProject, "net.neoforged:neoforge-dependencies"));
Expand All @@ -46,7 +48,7 @@ public void apply(Project project) {
project,
neoDevBuildDir,
extension.getRuns(),
writeNeoDevConfig,
neoForgeConfigOnly,
modulePath -> modulePath.getDependencies().add(modulePathDependency),
configureLegacyClasspath,
downloadAssets.flatMap(DownloadAssets::getAssetPropertiesFile)
Expand All @@ -60,7 +62,7 @@ public void apply(Project project) {
project,
neoDevBuildDir,
testTask,
writeNeoDevConfig,
neoForgeConfigOnly,
testExtension.getLoadedMods(),
testExtension.getTestedMod(),
modulePath -> modulePath.getDependencies().add(modulePathDependency),
Expand Down
39 changes: 15 additions & 24 deletions buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,23 @@ public void apply(Project project) {
*/

// 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.setGroup(INTERNAL_GROUP);
task.getUserDevConfig().set(neoDevBuildDir.map(dir -> dir.file("userdev-config.json")));
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));
});
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 -> {
Expand All @@ -140,7 +131,7 @@ public void apply(Project project) {
project,
neoDevBuildDir,
extension.getRuns(),
writeNeoDevConfig,
writeUserDevConfig,
modulePath -> {
modulePath.extendsFrom(configurations.moduleLibraries);
},
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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=5.0.1
fancy_mod_loader_version=5.0.6
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
Expand Down

0 comments on commit 3ddaffa

Please sign in to comment.