33import java .util .List ;
44import java .util .Objects ;
55import javax .inject .Inject ;
6- import net .neoforged .moddevgradle .legacyforge .internal .LegacyForgeModDevPlugin ;
76import net .neoforged .moddevgradle .legacyforge .internal .MinecraftMappings ;
8- import net .neoforged .moddevgradle .legacyforge .internal .SrgMappingsRule ;
97import net .neoforged .moddevgradle .legacyforge .tasks .RemapJar ;
108import net .neoforged .moddevgradle .legacyforge .tasks .RemapOperation ;
119import org .apache .commons .lang3 .StringUtils ;
1614import org .gradle .api .artifacts .ExternalModuleDependency ;
1715import org .gradle .api .artifacts .FileCollectionDependency ;
1816import org .gradle .api .artifacts .ProjectDependency ;
19- import org .gradle .api .artifacts .type .ArtifactTypeDefinition ;
2017import org .gradle .api .attributes .Attribute ;
2118import org .gradle .api .component .AdhocComponentWithVariants ;
2219import org .gradle .api .component .ConfigurationVariantDetails ;
@@ -36,7 +33,6 @@ public abstract class ObfuscationExtension {
3633 private final FileCollection extraMixinMappings ;
3734
3835 private final MinecraftMappings namedMappings ;
39- private final MinecraftMappings srgMappings ;
4036
4137 @ Inject
4238 public ObfuscationExtension (Project project ,
@@ -49,7 +45,6 @@ public ObfuscationExtension(Project project,
4945 this .extraMixinMappings = extraMixinMappings ;
5046
5147 this .namedMappings = project .getObjects ().named (MinecraftMappings .class , MinecraftMappings .NAMED );
52- this .srgMappings = project .getObjects ().named (MinecraftMappings .class , MinecraftMappings .SRG );
5348 }
5449
5550 private <T > Provider <T > assertConfigured (Provider <T > provider ) {
@@ -139,9 +134,12 @@ public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchive
139134 reobfConfig .setDescription ("The artifacts remapped to intermediate (SRG) Minecraft names for use in a production environment" );
140135 reobfConfig .getArtifacts ().clear (); // If this is called multiple times...
141136 for (var attribute : config .getAttributes ().keySet ()) {
142- copyAttribute (project , attribute , config , reobfConfig );
137+ // Don't copy the mappings attribute because we don't want to leak it in the published metadata
138+ // and there is no way to unset it later.
139+ if (attribute != MinecraftMappings .ATTRIBUTE ) {
140+ copyAttribute (project , attribute , config , reobfConfig );
141+ }
143142 }
144- reobfConfig .getAttributes ().attribute (MinecraftMappings .ATTRIBUTE , srgMappings );
145143 project .getArtifacts ().add (reobfConfig .getName (), reobf );
146144
147145 // Publish the reobf configuration instead of the original one to Maven
@@ -166,7 +164,7 @@ public Configuration createRemappingConfiguration(Configuration parent) {
166164 var remappingConfig = project .getConfigurations ().create ("mod" + StringUtils .capitalize (parent .getName ()), spec -> {
167165 spec .setDescription ("Configuration for dependencies of " + parent .getName () + " that needs to be remapped" );
168166 spec .setCanBeConsumed (false );
169- spec .setCanBeResolved (true );
167+ spec .setCanBeResolved (false );
170168 spec .setTransitive (false );
171169
172170 // Unfortunately, if we simply try to make the parent extend this config, transformations will not run because the parent doesn't request remapped deps
@@ -175,19 +173,12 @@ public Configuration createRemappingConfiguration(Configuration parent) {
175173 // Additionally, we force dependencies to be non-transitive since we cannot apply the attribute hack to transitive dependencies.
176174 spec .withDependencies (dependencies -> dependencies .forEach (dep -> {
177175 if (dep instanceof ExternalModuleDependency externalModuleDependency ) {
176+ project .getDependencies ().constraints (constraints -> {
177+ constraints .add (parent .getName (), externalModuleDependency .getGroup () + ":" + externalModuleDependency .getName () + ":" + externalModuleDependency .getVersion (), c -> {
178+ c .attributes (a -> a .attribute (MinecraftMappings .ATTRIBUTE , namedMappings ));
179+ });
180+ });
178181 externalModuleDependency .setTransitive (false );
179-
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-
186- // This rule ensures that this external module will be enriched with the attribute MAPPINGS=SRG
187- project .getDependencies ().getComponents ().withModule (
188- dep .getGroup () + ":" + dep .getName (), SrgMappingsRule .class , cfg -> {
189- cfg .params (srgMappings );
190- });
191182 } else if (dep instanceof FileCollectionDependency fileCollectionDependency ) {
192183 project .getDependencies ().constraints (constraints -> {
193184 constraints .add (parent .getName (), fileCollectionDependency .getFiles (), c -> {
@@ -204,16 +195,7 @@ public Configuration createRemappingConfiguration(Configuration parent) {
204195 }
205196 }));
206197 });
207-
208- var remappedDep = project .getDependencyFactory ().create (
209- remappingConfig .getIncoming ().artifactView (view -> {
210- 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 ));
213- }).getFiles ());
214- remappedDep .because ("Remapped mods from " + remappingConfig .getName ());
215-
216- parent .getDependencies ().add (remappedDep );
198+ parent .extendsFrom (remappingConfig );
217199
218200 return remappingConfig ;
219201 }
0 commit comments