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

Fix client data gen source set not depending on main when using split sources #1228

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