Skip to content

Commit 2b35f6c

Browse files
authored
Eagerly create dependency from version catalog (#981)
Fixes version catalog entries potentially being ignored by `fg.deobf` and/or any modifications from `DependencyHandler#variantOf`.
1 parent 6185579 commit 2b35f6c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/userdev/java/net/minecraftforge/gradle/userdev/DependencyManagementExtension.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.gradle.api.artifacts.ExternalModuleDependencyBundle;
2626
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
2727
import org.gradle.api.artifacts.repositories.ArtifactRepository;
28+
import org.gradle.api.provider.Property;
2829
import org.gradle.api.provider.Provider;
2930
import org.gradle.api.provider.ProviderConvertible;
3031
import org.gradle.api.publish.maven.MavenPublication;
@@ -91,16 +92,13 @@ public <T> Provider<?> deobf(
9192
@ClosureParams(value = SimpleType.class, options = "org.gradle.api.artifacts.ExternalModuleDependency")
9293
Closure<?> configure
9394
) {
94-
project.getDependencies().addProvider(UserDevPlugin.OBF, dependency, baseDependency -> {
95-
//noinspection ConstantValue -- null closure is allowed here
96-
if (configure != null)
97-
configure.call(baseDependency);
98-
});
99-
100-
// Checking for presence after DependencyHandler#addProvider so Gradle can throw its usual errors as needed
101-
if (!dependency.isPresent()) return dependency;
95+
if (dependency.isPresent() && dependency.get() instanceof ExternalModuleDependencyBundle) {
96+
project.getDependencies().addProvider(UserDevPlugin.OBF, dependency, baseDependency -> {
97+
//noinspection ConstantValue -- null closure is allowed here
98+
if (configure != null)
99+
configure.call(baseDependency);
100+
});
102101

103-
if (dependency.get() instanceof ExternalModuleDependencyBundle) {
104102
// this provider MUST return ExternalModuleDependencyBundle
105103
// The only way to coerce the type of it is to use a property, since we can set the type manually on creation.
106104
// ProviderInternal#getType uses the generic argument to determine what type it is.
@@ -117,7 +115,14 @@ public <T> Provider<?> deobf(
117115
return newBundle;
118116
}));
119117
} else {
120-
return dependency.map(d -> remapper.remap(project.getDependencies().create(d, configure)));
118+
// Rationale: single dependencies may have additional data that must be calculated at configuration time
119+
// The most obvious example being usage of DependencyHandler#variantOf.
120+
// If the dependency isn't created immediately, that information is lost when copying the base dependency (i don't know why)
121+
// It's a rather negligible performance hit and FG6 was already doing this anyway, so it's not a big deal.
122+
// Still going to return a Provider<?> though, since we also handle bundles in this method
123+
Property<Dependency> provider = project.getObjects().property(Dependency.class).value(dependency.map(d -> this.deobf(d, configure)));
124+
provider.finalizeValue();
125+
return provider;
121126
}
122127
}
123128

0 commit comments

Comments
 (0)