|
| 1 | +package juuxel.adorn.gradle; |
| 2 | + |
| 3 | +import net.fabricmc.loom.api.LoomGradleExtensionAPI; |
| 4 | +import org.gradle.api.Plugin; |
| 5 | +import org.gradle.api.Project; |
| 6 | +import org.gradle.api.plugins.JavaPluginExtension; |
| 7 | +import org.gradle.api.tasks.bundling.Jar; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | + |
| 11 | +public final class SplitSourcesSetupPlugin implements Plugin<Project> { |
| 12 | + @Override |
| 13 | + public void apply(Project project) { |
| 14 | + project.getPlugins().apply(MinecraftSetupPlugin.class); |
| 15 | + |
| 16 | + var loom = project.getExtensions().getByType(LoomGradleExtensionAPI.class); |
| 17 | + loom.splitEnvironmentSourceSets(); |
| 18 | + |
| 19 | + var sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); |
| 20 | + var client = sourceSets.getByName("client"); |
| 21 | + |
| 22 | + var clientJar = project.getTasks().register("clientJar", Jar.class, task -> { |
| 23 | + task.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("devlibs")); |
| 24 | + task.getArchiveClassifier().set("client"); |
| 25 | + task.from(client.getOutput()); |
| 26 | + }); |
| 27 | + |
| 28 | + var objects = project.getObjects(); |
| 29 | + project.getConfigurations().consumable("clientOutputs", config -> { |
| 30 | + config.getOutgoing().artifact(clientJar); |
| 31 | + |
| 32 | + config.getOutgoing().artifact(client.getOutput().getResourcesDir(), artifact -> { |
| 33 | + artifact.builtBy(client.getProcessResourcesTaskName()); |
| 34 | + }); |
| 35 | + |
| 36 | + for (File dir : client.getOutput().getClassesDirs()) { |
| 37 | + config.getOutgoing().artifact(dir, artifact -> { |
| 38 | + artifact.builtBy(client.getClassesTaskName()); |
| 39 | + }); |
| 40 | + } |
| 41 | + }); |
| 42 | + } |
| 43 | +} |
0 commit comments