Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always remap changing deps #1112

Open
wants to merge 1 commit into
base: exp/1.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -242,15 +245,23 @@ private static void createConstraints(ArtifactRef artifact, Configuration target

private static List<ArtifactRef> resolveArtifacts(Project project, Configuration configuration) {
final List<ArtifactRef> artifacts = new ArrayList<>();
final DependencySet allDependencies = configuration.getAllDependencies();
final List<String> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/projects/localFileDependency/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down