Skip to content

Commit 21b2cc7

Browse files
authored
Fix DependencyUtils failing to infer artifact classifier under some circumstances (such as artifact transforms) (#257)
1 parent e6008d5 commit 21b2cc7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/main/java/net/neoforged/moddevgradle/internal/utils/DependencyUtils.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package net.neoforged.moddevgradle.internal.utils;
22

3+
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
34
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
4-
import org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier;
55
import org.jetbrains.annotations.ApiStatus;
66

77
@ApiStatus.Internal
@@ -23,15 +23,15 @@ public static String guessMavenGav(ResolvedArtifactResult result) {
2323
filename = filename.substring(0, startOfExt);
2424
}
2525

26-
if (result.getId() instanceof ModuleComponentArtifactIdentifier moduleId) {
27-
var artifact = moduleId.getComponentIdentifier().getModule();
28-
var version = moduleId.getComponentIdentifier().getVersion();
26+
if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier moduleId) {
27+
var artifact = moduleId.getModule();
28+
var version = moduleId.getVersion();
2929
var expectedBasename = artifact + "-" + version;
3030

3131
if (filename.startsWith(expectedBasename + "-")) {
3232
classifier = filename.substring((expectedBasename + "-").length());
3333
}
34-
artifactId = moduleId.getComponentIdentifier().getGroup() + ":" + artifact + ":" + version;
34+
artifactId = moduleId.getGroup() + ":" + artifact + ":" + version;
3535
} else {
3636
// When we encounter a project reference, the component identifier does not expose the group or module name.
3737
// But we can access the list of capabilities associated with the published variant the artifact originates from.
@@ -40,7 +40,14 @@ public static String guessMavenGav(ResolvedArtifactResult result) {
4040
var capabilities = result.getVariant().getCapabilities();
4141
if (capabilities.size() == 1) {
4242
var capability = capabilities.get(0);
43-
artifactId = capability.getGroup() + ":" + capability.getName() + ":" + capability.getVersion();
43+
var artifact = capability.getName();
44+
var version = capability.getVersion();
45+
var expectedBasename = artifact + "-" + version;
46+
47+
if (filename.startsWith(expectedBasename + "-")) {
48+
classifier = filename.substring((expectedBasename + "-").length());
49+
}
50+
artifactId = capability.getGroup() + ":" + artifact + ":" + version;
4451
} else {
4552
artifactId = result.getId().getComponentIdentifier().toString();
4653
}

0 commit comments

Comments
 (0)