diff --git a/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java index 8de3103..60640cb 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java @@ -32,7 +32,8 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; -import java.util.stream.Collectors; + +import javax.annotation.Nullable; import com.google.gson.JsonObject; import org.apache.commons.io.FileUtils; @@ -42,7 +43,6 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.DependencySet; import org.gradle.api.artifacts.ProjectDependency; -import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.ResolvedConfiguration; import org.gradle.api.artifacts.ResolvedDependency; import org.gradle.api.tasks.bundling.AbstractArchiveTask; @@ -103,17 +103,17 @@ public final class NestedDependencyProvider implements NestedJarProvider { visited.add(dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion()); - // TODO change this to allow just normal jar tasks, so a project can have a none loom sub project Collection remapJarTasks = dependencyProject.getTasksByName("remapJar", false); Collection jarTasks = dependencyProject.getTasksByName("jar", false); for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) { - if (task instanceof RemapJarTask remapJarTask) { - File file = remapJarTask.getArchiveFile().get().getAsFile(); - fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file)); - } else if (task instanceof AbstractArchiveTask abstractArchiveTask) { - File file = abstractArchiveTask.getArchiveFile().get().getAsFile(); - fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file)); + if (task instanceof AbstractArchiveTask abstractArchiveTask) { + fileList.add(new DependencyInfo<>( + projectDependency, + new ProjectDependencyMetaExtractor(), + abstractArchiveTask.getArchiveFile().get().getAsFile(), + abstractArchiveTask.getArchiveClassifier().getOrNull() + )); } } } @@ -133,14 +133,13 @@ public final class NestedDependencyProvider implements NestedJarProvider { continue; } - List files = dependency - .getModuleArtifacts() - .stream() - .map(ResolvedArtifact::getFile) - .collect(Collectors.toList()); - - for (File file : files) { - fileList.add(new DependencyInfo<>(dependency, new ResolvedDependencyMetaExtractor(), file)); + for (var artifact : dependency.getModuleArtifacts()) { + fileList.add(new DependencyInfo<>( + dependency, + new ResolvedDependencyMetaExtractor(), + artifact.getFile(), + artifact.getClassifier() + )); } } @@ -195,7 +194,12 @@ public final class NestedDependencyProvider implements NestedJarProvider { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("schemaVersion", 1); - jsonObject.addProperty("id", (metaExtractor.group(dependency) + "_" + metaExtractor.name(dependency)).replaceAll("\\.", "_").toLowerCase(Locale.ENGLISH)); + + jsonObject.addProperty("id", + (metaExtractor.group(dependency) + "_" + metaExtractor.name(dependency) + info.getClassifierSuffix()) + .replaceAll("\\.", "_") + .toLowerCase(Locale.ENGLISH) + ); jsonObject.addProperty("version", metaExtractor.version(dependency)); jsonObject.addProperty("name", metaExtractor.name(dependency)); @@ -206,8 +210,8 @@ public final class NestedDependencyProvider implements NestedJarProvider { return LoomGradlePlugin.GSON.toJson(jsonObject); } - private record DependencyInfo(D dependency, DependencyMetaExtractor metaExtractor, File file) { - public void validateInputs() { + private record DependencyInfo(D dependency, DependencyMetaExtractor metaExtractor, File file, @Nullable String classifier) { + void validateInputs() { if (!file.exists()) { throw new RuntimeException("Failed to include nested jars, as it could not be found @ " + file.getAbsolutePath()); } @@ -216,6 +220,14 @@ public final class NestedDependencyProvider implements NestedJarProvider { throw new RuntimeException("Failed to include nested jars, as file was not a jar: " + file.getAbsolutePath()); } } + + String getClassifierSuffix() { + if (classifier == null) { + return ""; + } else { + return "_" + classifier; + } + } } private interface DependencyMetaExtractor {