Skip to content

Commit bf4f81f

Browse files
authored
Fix remapping of dependencies that have a classifier in the legacy plugin (#242)
1 parent 46c7224 commit bf4f81f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/legacy/java/net/neoforged/moddevgradle/legacyforge/dsl/ObfuscationExtension.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Objects;
55
import javax.inject.Inject;
6+
import net.neoforged.moddevgradle.legacyforge.internal.LegacyForgeModDevPlugin;
67
import net.neoforged.moddevgradle.legacyforge.internal.MinecraftMappings;
78
import net.neoforged.moddevgradle.legacyforge.internal.SrgMappingsRule;
89
import net.neoforged.moddevgradle.legacyforge.tasks.RemapJar;
@@ -15,6 +16,7 @@
1516
import org.gradle.api.artifacts.ExternalModuleDependency;
1617
import org.gradle.api.artifacts.FileCollectionDependency;
1718
import org.gradle.api.artifacts.ProjectDependency;
19+
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
1820
import org.gradle.api.attributes.Attribute;
1921
import org.gradle.api.component.AdhocComponentWithVariants;
2022
import org.gradle.api.component.ConfigurationVariantDetails;
@@ -175,6 +177,12 @@ public Configuration createRemappingConfiguration(Configuration parent) {
175177
if (dep instanceof ExternalModuleDependency externalModuleDependency) {
176178
externalModuleDependency.setTransitive(false);
177179

180+
// artifact dependencies need to be forced to be from our custom artifact type to be able
181+
// to inherit the mapping attribute (and be remapped). Module metadata doesn't apply here.
182+
for (var artifact : externalModuleDependency.getArtifacts()) {
183+
artifact.setType(LegacyForgeModDevPlugin.ARTIFACT_TYPE_SRG_JAR);
184+
}
185+
178186
// This rule ensures that this external module will be enriched with the attribute MAPPINGS=SRG
179187
project.getDependencies().getComponents().withModule(
180188
dep.getGroup() + ":" + dep.getName(), SrgMappingsRule.class, cfg -> {
@@ -200,11 +208,12 @@ public Configuration createRemappingConfiguration(Configuration parent) {
200208
var remappedDep = project.getDependencyFactory().create(
201209
remappingConfig.getIncoming().artifactView(view -> {
202210
view.attributes(a -> a.attribute(MinecraftMappings.ATTRIBUTE, namedMappings));
211+
// Forcing resolution to JAR here allows our SRG_JAR artifact transform to work
212+
view.attributes(a -> a.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE));
203213
}).getFiles());
204214
remappedDep.because("Remapped mods from " + remappingConfig.getName());
205215

206-
parent.getDependencies().add(
207-
remappedDep);
216+
parent.getDependencies().add(remappedDep);
208217

209218
return remappingConfig;
210219
}

src/legacy/java/net/neoforged/moddevgradle/legacyforge/internal/LegacyForgeModDevPlugin.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class LegacyForgeModDevPlugin implements Plugin<Project> {
4444

4545
public static final String CONFIGURATION_TOOL_ART = "autoRenamingToolRuntime";
4646
public static final String CONFIGURATION_TOOL_INSTALLERTOOLS = "installerToolsRuntime";
47+
public static final String ARTIFACT_TYPE_SRG_JAR = "srgJar";
4748

4849
private final MinecraftMappings namedMappings;
4950
private final MinecraftMappings srgMappings;
@@ -220,6 +221,20 @@ public void enable(Project project, LegacyForgeModdingSettings settings, LegacyF
220221
.attribute(MinecraftMappings.ATTRIBUTE, namedMappings)
221222
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE);
222223
});
224+
// This second copy of the transform is used for remapping artifact dependencies (i.e. on classifiers)
225+
// that circumvent the variant system.
226+
project.getDependencies().registerTransform(RemappingTransform.class, params -> {
227+
params.parameters(parameters -> {
228+
obf.configureSrgToNamedOperation(parameters.getRemapOperation());
229+
parameters.getMinecraftDependencies().from(remapDeps);
230+
});
231+
params.getFrom()
232+
.attribute(MinecraftMappings.ATTRIBUTE, srgMappings)
233+
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ARTIFACT_TYPE_SRG_JAR);
234+
params.getTo()
235+
.attribute(MinecraftMappings.ATTRIBUTE, namedMappings)
236+
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE);
237+
});
223238
}
224239

225240
private void configureDependencyRemapping(Project project, ObfuscationExtension obf) {
@@ -247,6 +262,10 @@ private void configureDependencyRemapping(Project project, ObfuscationExtension
247262
});
248263
});
249264

265+
// custom artifact type used to force remapping of artifact dependencies (which circumvent variant selection)
266+
project.getDependencies().getArtifactTypes().create(ARTIFACT_TYPE_SRG_JAR, artifactType -> {
267+
artifactType.getAttributes().attribute(MinecraftMappings.ATTRIBUTE, srgMappings);
268+
});
250269
obf.createRemappingConfiguration(project.getConfigurations().getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME));
251270
obf.createRemappingConfiguration(project.getConfigurations().getByName(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME));
252271
obf.createRemappingConfiguration(project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME));

0 commit comments

Comments
 (0)