diff --git a/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfProjectView.java b/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfProjectView.java index a2788cdf..e3214348 100644 --- a/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfProjectView.java +++ b/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfProjectView.java @@ -24,6 +24,8 @@ package net.fabricmc.loom.configuration.processors.speccontext; +import java.util.stream.Stream; + import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.file.ConfigurableFileCollection; @@ -32,6 +34,8 @@ import org.gradle.api.file.FileCollection; public interface DeobfProjectView extends ProjectView { FileCollection getDependencies(DebofConfiguration debofConfiguration, DebofConfiguration.TargetSourceSet targetSourceSet); + Stream getProjectDependencies(DebofConfiguration debofConfiguration); + FileCollection getFullClasspath(); class Impl extends AbstractProjectView implements DeobfProjectView { @@ -44,6 +48,12 @@ public interface DeobfProjectView extends ProjectView { return debofConfiguration.getConfiguration(project, targetSourceSet); } + @Override + public Stream getProjectDependencies(DebofConfiguration debofConfiguration) { + return debofConfiguration.getConfigurations(project).stream() + .flatMap(configuration -> getLoomProjectDependencies(configuration.getName())); + } + @Override public FileCollection getFullClasspath() { ConfigurableFileCollection classpath = project.files(); diff --git a/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfSpecContext.java b/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfSpecContext.java index 750394a7..c18d067c 100644 --- a/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfSpecContext.java +++ b/src/main/java/net/fabricmc/loom/configuration/processors/speccontext/DeobfSpecContext.java @@ -28,6 +28,7 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -36,6 +37,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; import org.gradle.api.Project; import org.gradle.api.file.FileCollection; @@ -89,10 +91,16 @@ public record DeobfSpecContext(List modDependencies, clientTransformingModIds = Set.of(); } + // All dependency mods that are on both the compile and runtime classpath + List modDependenciesCompileRuntime = new ArrayList<>(getMods(mods, combine(mainTransformingModIds, clientTransformingModIds))); + + // Add all of the project depedencies that are on both the compile and runtime classpath + modDependenciesCompileRuntime.addAll(getCompileRuntimeProjectMods(projectView, fmjCache)); + return new DeobfSpecContext( dependentMods, projectView.getMods(), - getMods(mods, combine(mainTransformingModIds, clientTransformingModIds)), + modDependenciesCompileRuntime, getMods(mods, onlyInLeft(clientTransformingModIds, mainTransformingModIds)) ); } @@ -157,6 +165,34 @@ public record DeobfSpecContext(List modDependencies, return result; } + // Returns a list of mods that are on both to compile and runtime classpath + private static List getCompileRuntimeProjectMods(DeobfProjectView projectView, AsyncCache> fmjCache) { + var mods = new ArrayList(); + + for (Project dependentProject : getCompileRuntimeProjectDependencies(projectView).toList()) { + List projectMods = fmjCache.getBlocking(dependentProject.getPath(), () -> { + return FabricModJsonHelpers.getModsInProject(dependentProject); + }); + + mods.addAll(projectMods); + } + + return Collections.unmodifiableList(mods); + } + + // Returns a list of Loom Projects found in both the runtime and compile classpath + private static Stream getCompileRuntimeProjectDependencies(DeobfProjectView projectView) { + if (projectView.disableProjectDependantMods()) { + return Stream.empty(); + } + + final Stream runtimeProjects = projectView.getProjectDependencies(DebofConfiguration.RUNTIME); + final List compileProjects = projectView.getProjectDependencies(DebofConfiguration.COMPILE).toList(); + + return runtimeProjects + .filter(compileProjects::contains); // Use the intersection of the two configurations. + } + private static Set common(Set a, Set b) { Set copy = new HashSet<>(a); copy.retainAll(b);