1010import groovy .transform .NamedVariant ;
1111import net .minecraftforge .accesstransformers .gradle .ArtifactAccessTransformer ;
1212import net .minecraftforge .gradleutils .shared .Closures ;
13+ import net .minecraftforge .util .os .OS ;
1314import org .gradle .api .Action ;
1415import org .gradle .api .InvalidUserCodeException ;
1516import org .gradle .api .Project ;
1617import org .gradle .api .artifacts .Configuration ;
1718import org .gradle .api .artifacts .Dependency ;
1819import org .gradle .api .artifacts .ExternalModuleDependency ;
20+ import org .gradle .api .artifacts .ModuleIdentifier ;
1921import org .gradle .api .artifacts .type .ArtifactTypeDefinition ;
2022import org .gradle .api .attributes .Attribute ;
2123import org .gradle .api .attributes .AttributeContainer ;
2224import org .gradle .api .attributes .Category ;
2325import org .gradle .api .file .Directory ;
2426import org .gradle .api .file .ProjectLayout ;
2527import org .gradle .api .file .RegularFileProperty ;
26- import org .gradle .api .logging .LogLevel ;
2728import org .gradle .api .model .ObjectFactory ;
2829import org .gradle .api .plugins .ExtensionAware ;
2930import org .gradle .api .plugins .JavaPluginExtension ;
3334import org .gradle .api .tasks .SourceSet ;
3435import org .gradle .api .tasks .TaskProvider ;
3536import org .gradle .api .tasks .compile .JavaCompile ;
36- import org .gradle .internal .os .OperatingSystem ;
37- import org .gradle .nativeplatform .OperatingSystemFamily ;
3837import org .jetbrains .annotations .Nullable ;
39- import org .jetbrains .annotations .UnknownNullability ;
4038
4139import javax .inject .Inject ;
4240import java .io .File ;
4341import java .util .Map ;
4442import java .util .Objects ;
43+ import java .util .Set ;
4544
4645abstract class MinecraftDependencyImpl implements MinecraftDependencyInternal {
47- private @ UnknownNullability ExternalModuleDependency delegate ;
48- private @ UnknownNullability TaskProvider <SyncMavenizer > mavenizer ;
46+ private transient @ Nullable ("configuration cache" ) ExternalModuleDependency delegate ;
47+ private transient @ Nullable ("configuration cache" ) TaskProvider <SyncMavenizer > mavenizer ;
48+
49+ final Property <String > asString = getObjects ().property (String .class );
50+ final Property <String > asPath = getObjects ().property (String .class );
51+ final Property <ModuleIdentifier > module = getObjects ().property (ModuleIdentifier .class );
52+ final Property <String > version = getObjects ().property (String .class );
4953
5054 private final Provider <? extends Directory > mavenizerOutput ;
5155 private final Property <MinecraftMappings > mappings ;
@@ -70,12 +74,12 @@ public MinecraftDependencyImpl(Provider<? extends Directory> mavenizerOutput) {
7074 }
7175
7276 @ Override
73- public ExternalModuleDependency asDependency () {
77+ public @ Nullable ( "configuration cache" ) ExternalModuleDependency asDependency () {
7478 return this .delegate ;
7579 }
7680
7781 @ Override
78- public TaskProvider <SyncMavenizer > asTask () {
82+ public @ Nullable ( "configuration cache" ) TaskProvider <SyncMavenizer > asTask () {
7983 return this .mavenizer ;
8084 }
8185
@@ -97,13 +101,18 @@ public ExternalModuleDependency init(Object dependencyNotation, Closure<?> closu
97101
98102 this .mavenizer = SyncMavenizer .register (getProject (), dependency , this .mappings , mavenizerOutput );
99103
104+ this .asString .set (dependency .toString ());
105+ this .asPath .set (Util .pathify (dependency ));
106+ this .module .set (dependency .getModule ());
107+ this .version .set (dependency .getVersion ());
108+
100109 return this .delegate = dependency ;
101110 }
102111
103112 @ Override
104113 public Action <? super AttributeContainer > addAttributes () {
105114 return attributes -> {
106- attributes .attribute (MinecraftExtension .Attributes .os , this . getObjects ().named ( OperatingSystemFamily .class , OperatingSystem . current (). getFamilyName ( )));
115+ attributes .attributeProvider (MinecraftExtension .Attributes .os , getProviders ().of ( OperatingSystemName .class , spec -> spec . parameters ( parameters -> parameters . getAllowedOperatingSystems (). set ( Set . of ( OS . WINDOWS , OS . MACOS , OS . LINUX )) )));
107116 attributes .attributeProvider (MinecraftExtension .Attributes .mappingsChannel , mappings .map (MinecraftMappings ::channel ));
108117 attributes .attributeProvider (MinecraftExtension .Attributes .mappingsVersion , mappings .map (MinecraftMappings ::version ));
109118 };
@@ -114,9 +123,8 @@ public void handle(Configuration configuration) {
114123 if (!configuration .isCanBeResolved ()) return ;
115124
116125 this .mappings .finalizeValue ();
117- var dependency = this .asDependency ();
118126 configuration .getResolutionStrategy ().dependencySubstitution (s -> {
119- var moduleSelector = "%s:%s" .formatted (dependency . getModule (), dependency . getVersion ());
127+ var moduleSelector = "%s:%s" .formatted (this . module . get (), this . version . get ());
120128 var module = s .module (moduleSelector );
121129 try {
122130 s .substitute (module )
@@ -127,12 +135,15 @@ public void handle(Configuration configuration) {
127135 }
128136 });
129137
138+ var asDependency = this .asDependency ();
139+ if (asDependency == null ) return ;
140+
130141 var hierarchy = configuration .getHierarchy ();
131142
132143 var sourceSet = Util .getSourceSet (
133144 getProject ().getConfigurations ().matching (hierarchy ::contains ),
134145 getProject ().getExtensions ().getByType (JavaPluginExtension .class ).getSourceSets (),
135- this . asDependency ()
146+ asDependency
136147 );
137148
138149 // Hope that this is handled elsewhere, and that we are transitive.
@@ -145,9 +156,9 @@ public void handle(Configuration configuration) {
145156 public void handle (SourceSet sourceSet ) {
146157 getProject ().getTasks ().named (sourceSet .getCompileJavaTaskName (), JavaCompile .class , task -> {
147158 task .doFirst (t -> {
148- var file = this .mavenizerOutput .map (dir -> dir .dir (Util . pathify ( asDependency ())) ).get ().getAsFile ();
159+ var file = this .mavenizerOutput .map (dir -> dir .dir (this . asPath )). get ( ).get ().getAsFile ();
149160 if (!file .exists ())
150- throw this .problems .mavenizerOutOfDateCompile (asDependency ());
161+ throw this .problems .mavenizerOutOfDateCompile (this . asString . get ());
151162 });
152163 });
153164
@@ -223,7 +234,10 @@ public Action<? super AttributeContainer> addAttributes() {
223234 public void handle (SourceSet sourceSet ) {
224235 super .handle (sourceSet );
225236
226- if (!Util .contains (getProject ().getConfigurations (), sourceSet , false , this .asDependency ())) return ;
237+ var asDependency = this .asDependency ();
238+ if (asDependency == null ) return ;
239+
240+ if (!Util .contains (getProject ().getConfigurations (), sourceSet , false , asDependency )) return ;
227241 if (!this .atPath .isPresent ()) return ;
228242
229243 var itor = sourceSet .getResources ().getSrcDirs ().iterator ();
@@ -235,7 +249,7 @@ public void handle(SourceSet sourceSet) {
235249 this .atFile .convention (this .getProjectLayout ().getProjectDirectory ().file (this .getProviders ().provider (() -> "src/%s/resources/%s" .formatted (sourceSet .getName (), this .atPath .get ()))).get ());
236250 }
237251
238- ArtifactAccessTransformer .validateConfig (getProject (), this . asDependency () , this .atFile );
252+ ArtifactAccessTransformer .validateConfig (getProject (), asDependency , this .atFile );
239253 }
240254
241255 private Attribute <Boolean > registerTransform () {
0 commit comments