Skip to content

Commit

Permalink
Fix client data gen source set not depending on main when using split…
Browse files Browse the repository at this point in the history
… sources (#1228)

* Fix client data gen not depending on main when using split sources

* Also don't delete datagen output on clean

* Checkstyle
  • Loading branch information
modmuss50 authored Dec 2, 2024
1 parent 1d0946f commit c80333b
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,31 +133,18 @@ public void configureDataGeneration(Action<DataGenerationSettings> 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(() -> {
Expand Down Expand Up @@ -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());
}
}

0 comments on commit c80333b

Please sign in to comment.