From c80333b2bd4806ceb2c68585a51f864ec6ef5bb2 Mon Sep 17 00:00:00 2001 From: modmuss Date: Mon, 2 Dec 2024 18:02:37 +0000 Subject: [PATCH] Fix client data gen source set not depending on main when using split sources (#1228) * Fix client data gen not depending on main when using split sources * Also don't delete datagen output on clean * Checkstyle --- .../configuration/FabricApiExtension.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java b/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java index de5cb074f..26d6b271a 100644 --- a/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java +++ b/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java @@ -44,12 +44,10 @@ import org.gradle.api.file.RegularFileProperty; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.provider.Property; -import org.gradle.api.tasks.Delete; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.TaskContainer; import org.gradle.jvm.tasks.Jar; -import org.gradle.language.base.plugins.LifecycleBasePlugin; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -135,31 +133,18 @@ public void configureDataGeneration(Action action) { jar.exclude(".cache/**"); }); - taskContainer.getByName(LifecycleBasePlugin.CLEAN_TASK_NAME, task -> { - Delete clean = (Delete) task; - clean.delete(outputDirectory); - }); - if (settings.getCreateSourceSet().get()) { final boolean isClientAndSplit = extension.areEnvironmentSourceSetsSplit() && settings.getClient().get(); - final SourceSet targetSourceSet = isClientAndSplit ? SourceSetHelper.getSourceSetByName(MinecraftSourceSets.Split.CLIENT_ONLY_SOURCE_SET_NAME, getProject()) : mainSourceSet; SourceSetContainer sourceSets = SourceSetHelper.getSourceSets(getProject()); // Create the new datagen sourceset, depend on the main or client sourceset. SourceSet dataGenSourceSet = sourceSets.create(DATAGEN_SOURCESET_NAME, sourceSet -> { - sourceSet.setCompileClasspath( - sourceSet.getCompileClasspath() - .plus(targetSourceSet.getOutput()) - ); - - sourceSet.setRuntimeClasspath( - sourceSet.getRuntimeClasspath() - .plus(targetSourceSet.getOutput()) - ); - - extendsFrom(getProject(), sourceSet.getCompileClasspathConfigurationName(), targetSourceSet.getCompileClasspathConfigurationName()); - extendsFrom(getProject(), sourceSet.getRuntimeClasspathConfigurationName(), targetSourceSet.getRuntimeClasspathConfigurationName()); + dependsOn(sourceSet, mainSourceSet); + + if (isClientAndSplit) { + dependsOn(sourceSet, SourceSetHelper.getSourceSetByName(MinecraftSourceSets.Split.CLIENT_ONLY_SOURCE_SET_NAME, getProject())); + } }); settings.getModId().convention(getProject().provider(() -> { @@ -341,4 +326,19 @@ private static void extendsFrom(Project project, String name, String extendsFrom configuration.extendsFrom(configurations.getByName(extendsFrom)); }); } + + private void dependsOn(SourceSet sourceSet, SourceSet other) { + sourceSet.setCompileClasspath( + sourceSet.getCompileClasspath() + .plus(other.getOutput()) + ); + + sourceSet.setRuntimeClasspath( + sourceSet.getRuntimeClasspath() + .plus(other.getOutput()) + ); + + extendsFrom(getProject(), sourceSet.getCompileClasspathConfigurationName(), other.getCompileClasspathConfigurationName()); + extendsFrom(getProject(), sourceSet.getRuntimeClasspathConfigurationName(), other.getRuntimeClasspathConfigurationName()); + } }