Fix DependencyDownloader to not include two versions of the same dependency

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2022-03-02 11:34:39 +08:00
parent edc3c82175
commit e38fa2ef72
2 changed files with 17 additions and 11 deletions

View File

@@ -296,7 +296,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
}
private Set<File> minecraftClasspath() {
return DependencyDownloader.resolveFiles(getProject().getConfigurations().getByName(Constants.Configurations.FORGE_RUNTIME_LIBRARY), true);
return DependencyDownloader.resolveFiles(getProject(), getProject().getConfigurations().getByName(Constants.Configurations.FORGE_RUNTIME_LIBRARY), true);
}
public File getUserdevJar() {

View File

@@ -25,7 +25,8 @@
package net.fabricmc.loom.util;
import java.io.File;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.gradle.api.Project;
@@ -69,16 +70,21 @@ public final class DependencyDownloader {
return files;
}
private static Set<File> resolve(Configuration configuration, boolean transitive) {
Configuration copy = configuration.copy();
copy.setTransitive(transitive);
Set<File> files = new LinkedHashSet<>(copy.resolve());
private static List<Dependency> collectDependencies(Configuration configuration) {
List<Dependency> dependencies = new ArrayList<>();
for (Configuration extendsForm : configuration.getExtendsFrom()) {
files.addAll(resolve(extendsForm, transitive));
for (Configuration extendsFrom : configuration.getExtendsFrom()) {
dependencies.addAll(collectDependencies(extendsFrom));
}
return files;
dependencies.addAll(configuration.getDependencies());
return dependencies;
}
private static Configuration copyWith(Project project, Configuration configuration, boolean transitive) {
Configuration copy = project.getConfigurations().detachedConfiguration(collectDependencies(configuration).toArray(new Dependency[0]));
copy.setTransitive(transitive);
return copy;
}
/**
@@ -91,7 +97,7 @@ public final class DependencyDownloader {
* @param transitive true if transitive dependencies should be included, false otherwise
* @return a mutable set containing the resolved files of the configuration
*/
public static Set<File> resolveFiles(Configuration configuration, boolean transitive) {
return resolve(configuration, transitive);
public static Set<File> resolveFiles(Project project, Configuration configuration, boolean transitive) {
return copyWith(project, configuration, transitive).resolve();
}
}