Make the sub project requirement a bit more intelligent, no longer blindly depends on all sub projects.

dev/0.11
modmuss50 2019-04-07 20:38:10 +01:00
parent 0d92da79c6
commit 4b9db57aaa
2 changed files with 24 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import net.fabricmc.loom.task.RemapJar;
import net.fabricmc.loom.task.RemapSourcesJar;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.LoomDependencyManager;
import net.fabricmc.loom.util.NestedJars;
import net.fabricmc.loom.util.SetupIntelijRunConfigs;
import org.gradle.api.*;
import org.gradle.api.artifacts.Configuration;
@ -50,6 +51,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
public class AbstractPlugin implements Plugin<Project> {
protected Project project;
@ -266,7 +268,7 @@ public class AbstractPlugin implements Plugin<Project> {
remapJarTask.dependsOn(project1.getTasks().getByName("jar"));
project1.getTasks().getByName("build").dependsOn(remapJarTask);
//Run all the sub project remap jars tasks before the root projects jar, this is to allow us to include projects
project1.subprojects(subProject -> remapJarTask.dependsOn(subProject.getTasksByName("remapJar", false)));
NestedJars.getRequiredTasks(project1).forEach(remapJarTask::dependsOn);
try {
AbstractArchiveTask sourcesTask = (AbstractArchiveTask) project1.getTasks().getByName("sourcesJar");

View File

@ -44,6 +44,7 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.zip.ZipEntry;
@ -112,6 +113,26 @@ public class NestedJars {
return fileList;
}
//Looks for any deps that require a sub project to be built first
public static List<RemapJar> getRequiredTasks(Project project){
List<RemapJar> remapTasks = new ArrayList<>();
Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE);
DependencySet dependencies = configuration.getDependencies();
for (Dependency dependency : dependencies) {
if (dependency instanceof ProjectDependency) {
ProjectDependency projectDependency = (ProjectDependency) dependency;
Project dependencyProject = projectDependency.getDependencyProject();
for (Task task : dependencyProject.getTasksByName("remapJar", false)) {
if (task instanceof RemapJar) {
remapTasks.add((RemapJar) task);
}
}
}
}
return remapTasks;
}
private static ZipEntryTransformerEntry[] single(ZipEntryTransformerEntry element) {
return new ZipEntryTransformerEntry[]{element};
}