Skip to content

Commit

Permalink
localRuntime and localImplementation convention configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Oct 28, 2024
1 parent e20ed35 commit eb33805
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/dev/lukebemish/crochet/internal/CrochetPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import org.gradle.api.attributes.MultipleCandidatesDetails;
import org.gradle.api.attributes.java.TargetJvmVersion;
import org.gradle.api.logging.configuration.ShowStacktrace;
import org.gradle.api.tasks.SourceSetContainer;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;

public class CrochetPlugin implements Plugin<Project> {
// TODO: re-implement this stuff
public static final String LOCAL_RUNTIME_CONFIGURATION_NAME = "localRuntime";
public static final String TASK_GRAPH_RUNNER_CONFIGURATION_NAME = "crochetTaskGraphRunnerClasspath";
public static final String TASK_GRAPH_RUNNER_TOOLS_CONFIGURATION_NAME = "crochetTaskGraphRunnerDependencies";
public static final String DEV_LAUNCH_CONFIGURATION_NAME = "crochetDevLaunchClasspath";
Expand Down Expand Up @@ -87,6 +86,9 @@ public void apply(@NotNull Project project) {
project.getConfigurations().register(TERMINAL_CONSOLE_APPENDER_CONFIGURATION_NAME);
project.getDependencies().add(TERMINAL_CONSOLE_APPENDER_CONFIGURATION_NAME, "net.minecrell:terminalconsoleappender:" + Versions.TERMINAL_CONSOLE_APPENDER);

// configurations
setupConventionalConfigurations(project);

var extension = project.getExtensions().create("crochet", CrochetExtension.class, project);

project.getGradle().getSharedServices().registerIfAbsent("taskGraphRunnerDaemon", TaskGraphRunnerService.class, spec -> {
Expand All @@ -100,6 +102,21 @@ public void apply(@NotNull Project project) {
applyDisambiguationRules(project);
}

private static void setupConventionalConfigurations(Project project) {
var sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
sourceSets.configureEach(sourceSet -> {
var compileClasspath = project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName());
var runtimeClasspath = project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName());

var localRuntime = project.getConfigurations().maybeCreate(sourceSet.getTaskName(null, "localRuntime"));
runtimeClasspath.extendsFrom(localRuntime);

var localImplementation = project.getConfigurations().maybeCreate(sourceSet.getTaskName(null, "localImplementation"));
compileClasspath.extendsFrom(localImplementation);
runtimeClasspath.extendsFrom(localImplementation);
});
}

private static void applyDisambiguationRules(Project project) {
project.getDependencies().attributesSchema(attributesSchema -> {
attributesSchema.attribute(DISTRIBUTION_ATTRIBUTE).getDisambiguationRules().add(DistributionDisambiguationRule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@ private void forFeatureShared(SourceSet sourceSet, Action<FabricSourceSetDepende
var modLocalRuntime = project.getConfigurations().maybeCreate(sourceSet.getTaskName("mod", "localRuntime"));
modLocalRuntime.fromDependencyCollector(dependencies.getModLocalRuntime());
modRuntimeClasspath.extendsFrom(modLocalRuntime);
var modLocalImplementation = project.getConfigurations().maybeCreate(sourceSet.getTaskName("mod", "localImplementation"));
modLocalImplementation.fromDependencyCollector(dependencies.getModLocalImplementation());
modCompileClasspath.extendsFrom(modLocalImplementation);
modRuntimeClasspath.extendsFrom(modLocalImplementation);
var modImplementation = project.getConfigurations().maybeCreate(sourceSet.getTaskName("mod", "implementation"));
modImplementation.fromDependencyCollector(dependencies.getModImplementation());
modCompileClasspath.extendsFrom(modImplementation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public abstract class FabricSourceSetDependencies implements Dependencies {
public abstract DependencyCollector getModCompileOnlyApi();
public abstract DependencyCollector getModRuntimeOnly();
public abstract DependencyCollector getModLocalRuntime();
public abstract DependencyCollector getModLocalImplementation();
public abstract DependencyCollector getModImplementation();
public abstract DependencyCollector getModApi();
}

0 comments on commit eb33805

Please sign in to comment.