1919import org .gradle .api .file .RegularFile ;
2020import org .gradle .api .file .RegularFileProperty ;
2121import org .gradle .api .model .ObjectFactory ;
22+ import org .gradle .api .plugins .ExtensionAware ;
2223import org .gradle .api .plugins .ExtraPropertiesExtension .UnknownPropertyException ;
2324import org .gradle .api .provider .Property ;
2425import org .gradle .api .provider .Provider ;
@@ -63,6 +64,23 @@ public Provider<ExternalModuleDependency> getDelegate() {
6364 }
6465
6566 Provider <ExternalModuleDependency > setDelegate (Object dependencyNotation , Closure <?> closure ) {
67+ var hash = this .hashCode ();
68+
69+ this .project .afterEvaluate (project -> project .getConfigurations ().forEach (configuration -> {
70+ configuration .getDependencies ().matching (dependency -> {
71+ var ext = ((ExtensionAware ) dependency ).getExtensions ().getExtraProperties ();
72+ return ext .has ("__mc_dep_hash" ) && (int ) ext .get ("__mc_dep_hash" ) == hash ;
73+ }).configureEach (dependency -> configuration .getDependencyConstraints ().add (this .project .getDependencies ().getConstraints ().create (((ExternalModuleDependency ) dependency ).getModule ().toString (), constraint -> {
74+ constraint .because ("Accounts for mappings used and natives variants" );
75+
76+ constraint .attributes (attributes -> {
77+ attributes .attribute (MinecraftExtension .Attributes .os , this .getObjects ().named (OperatingSystemFamily .class , OperatingSystem .current ().getFamilyName ()));
78+ attributes .attributeProvider (MinecraftExtension .Attributes .mappingsChannel , mappings .map (MinecraftMappings ::channel ));
79+ attributes .attributeProvider (MinecraftExtension .Attributes .mappingsVersion , mappings .map (MinecraftMappings ::version ));
80+ });
81+ })));
82+ }));
83+
6684 return this .delegate = this .getObjects ().property (ExternalModuleDependency .class ).value (this .getProviders ().provider (
6785 () -> (ExternalModuleDependency ) this .project .getDependencies ().create (dependencyNotation , Closures .<Dependency , ExternalModuleDependency >function (dependency -> {
6886 if (!(dependency instanceof ExternalModuleDependency module ))
@@ -73,21 +91,7 @@ Provider<ExternalModuleDependency> setDelegate(Object dependencyNotation, Closur
7391
7492 Closures .invoke (this .closure (closure ), module );
7593
76- var mappings = this .getMappings ();
77-
78- this .project .getConfigurations ().forEach (configuration -> {
79- if (!configuration .isCanBeDeclared ()) return ;
80-
81- configuration .getDependencyConstraints ().add (this .project .getDependencies ().getConstraints ().create (module .getModule ().toString (), constraint -> {
82- constraint .because ("Accounts for mappings used and natives variants" );
83-
84- constraint .attributes (attributes -> {
85- attributes .attribute (MinecraftExtension .Attributes .os , this .getObjects ().named (OperatingSystemFamily .class , OperatingSystem .current ().getFamilyName ()));
86- attributes .attribute (MinecraftExtension .Attributes .mappingsChannel , mappings .channel ());
87- attributes .attribute (MinecraftExtension .Attributes .mappingsVersion , mappings .version ());
88- });
89- }));
90- });
94+ ((ExtensionAware ) module ).getExtensions ().getExtraProperties ().set ("__mc_dep_hash" , hash );
9195
9296 return module ;
9397 }))
0 commit comments