From 9ab752af8da2370f9627be4eb3121567b8ae9bb2 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 29 Apr 2024 23:07:23 +0100 Subject: [PATCH] Always remap changing deps --- .../loom/configuration/mods/ArtifactRef.java | 9 ++++++++- .../mods/ModConfigurationRemapper.java | 15 +++++++++++++-- .../mods/dependency/SimpleModDependency.java | 2 +- .../mods/dependency/SplitModDependency.java | 4 ++++ .../projects/localFileDependency/build.gradle | 5 +++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactRef.java b/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactRef.java index b5c9ca8dd..e7cac3ab7 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactRef.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactRef.java @@ -52,9 +52,11 @@ public interface ArtifactRef { @Nullable String classifier(); + boolean changing(); + void applyToConfiguration(Project project, Configuration configuration); - record ResolvedArtifactRef(ResolvedArtifact artifact, @Nullable Path sources) implements ArtifactRef { + record ResolvedArtifactRef(ResolvedArtifact artifact, @Nullable Path sources, boolean changing) implements ArtifactRef { @Override public Path path() { return artifact.getFile().toPath(); @@ -101,6 +103,11 @@ record FileArtifactRef(Path path, String group, String name, String version) imp return null; } + @Override + public boolean changing() { + return false; + } + @Override public void applyToConfiguration(Project project, Configuration configuration) { final DependencyHandler dependencies = project.getDependencies(); diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java b/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java index 61a4d8443..0c0eb5186 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java @@ -40,7 +40,10 @@ import com.google.common.collect.ImmutableMap; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.DependencySet; +import org.gradle.api.artifacts.ExternalModuleDependency; import org.gradle.api.artifacts.FileCollectionDependency; +import org.gradle.api.artifacts.ModuleVersionIdentifier; import org.gradle.api.artifacts.MutableVersionConstraint; import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.dsl.DependencyHandler; @@ -242,15 +245,23 @@ private static void createConstraints(ArtifactRef artifact, Configuration target private static List resolveArtifacts(Project project, Configuration configuration) { final List artifacts = new ArrayList<>(); + final DependencySet allDependencies = configuration.getAllDependencies(); + final List changingDependencies = allDependencies.withType(ExternalModuleDependency.class) + .matching(ExternalModuleDependency::isChanging) + .stream() + .map(dependency -> "%s:%s:%s".formatted(dependency.getGroup(), dependency.getName(), dependency.getVersion())) + .toList(); for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) { final Path sources = findSources(project, artifact); - artifacts.add(new ArtifactRef.ResolvedArtifactRef(artifact, sources)); + final ModuleVersionIdentifier moduleId = artifact.getModuleVersion().getId(); + final String id = "%s:%s:%s".formatted(moduleId.getGroup(), moduleId.getName(), moduleId.getVersion()); + artifacts.add(new ArtifactRef.ResolvedArtifactRef(artifact, sources, changingDependencies.contains(id))); } // FileCollectionDependency (files/fileTree) doesn't resolve properly, // so we have to "resolve" it on our own. The naming is "abc.jar" => "unspecified:abc:unspecified". - for (FileCollectionDependency dependency : configuration.getAllDependencies().withType(FileCollectionDependency.class)) { + for (FileCollectionDependency dependency : allDependencies.withType(FileCollectionDependency.class)) { final String group = replaceIfNullOrEmpty(dependency.getGroup(), () -> MISSING_GROUP); final FileCollection files = dependency.getFiles(); diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SimpleModDependency.java b/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SimpleModDependency.java index 34c82cf3e..cefd0a7e2 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SimpleModDependency.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SimpleModDependency.java @@ -48,7 +48,7 @@ public SimpleModDependency(ArtifactRef artifact, ArtifactMetadata metadata, Stri @Override public boolean isCacheInvalid(Project project, @Nullable String variant) { - return !maven.exists(variant); + return getInputArtifact().changing() || !maven.exists(variant); } @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SplitModDependency.java b/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SplitModDependency.java index 7f088357d..f871b1b62 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SplitModDependency.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/dependency/SplitModDependency.java @@ -59,6 +59,10 @@ public SplitModDependency(ArtifactRef artifact, ArtifactMetadata metadata, Strin @Override public boolean isCacheInvalid(Project project, @Nullable String variant) { + if (getInputArtifact().changing()) { + return true; + } + boolean exists = switch (target) { case COMMON_ONLY -> getCommonMaven().exists(variant); case CLIENT_ONLY -> getClientMaven().exists(variant); diff --git a/src/test/resources/projects/localFileDependency/build.gradle b/src/test/resources/projects/localFileDependency/build.gradle index 289b50635..cf5600156 100644 --- a/src/test/resources/projects/localFileDependency/build.gradle +++ b/src/test/resources/projects/localFileDependency/build.gradle @@ -31,6 +31,11 @@ dependencies { modImplementation fileTree("myFileTree") // an entire file tree modImplementation name: "test-data-e" // a flatDir dependency + // Test changing + modImplementation("net.fabricmc:fabric-loom-native-support:1.0.0") { + changing = true + } + // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. }