Skip to content

Commit d0826fe

Browse files
authored
Fix compatibility with Gradle 9 (#264)
1 parent e3d0235 commit d0826fe

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
id 'maven-publish'
88
id 'net.neoforged.gradleutils'
99
id 'com.gradle.plugin-publish' version '1.2.1'
10-
id 'com.gradleup.shadow' version '8.3.0'
10+
id 'com.gradleup.shadow' version '9.0.0-beta15'
1111
}
1212

1313
group = 'net.neoforged'

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public Configuration createRemappingConfiguration(Configuration parent) {
186186
});
187187
} else if (dep instanceof ProjectDependency projectDependency) {
188188
project.getDependencies().constraints(constraints -> {
189-
constraints.add(parent.getName(), projectDependency.getDependencyProject(), c -> {
189+
constraints.add(parent.getName(), getProjectDependencyProject(project, projectDependency), c -> {
190190
c.attributes(a -> a.attribute(MinecraftMappings.ATTRIBUTE, namedMappings));
191191
});
192192
});
@@ -198,4 +198,21 @@ public Configuration createRemappingConfiguration(Configuration parent) {
198198

199199
return remappingConfig;
200200
}
201+
202+
private static Project getProjectDependencyProject(Project project, ProjectDependency projectDependency) {
203+
// Gradle 9 requires using getPath(), but it was only added in 8.11, and we currently target 8.9
204+
try {
205+
var clazz = ProjectDependency.class;
206+
try {
207+
var getPathMethod = clazz.getMethod("getPath");
208+
var path = (String) getPathMethod.invoke(projectDependency);
209+
return project.project(path);
210+
} catch (NoSuchMethodException ignored) {
211+
var getDependencyProjectMethod = clazz.getMethod("getDependencyProject");
212+
return (Project) getDependencyProjectMethod.invoke(projectDependency);
213+
}
214+
} catch (ReflectiveOperationException exception) {
215+
throw new RuntimeException("Failed to access project of ProjectDependency", exception);
216+
}
217+
}
201218
}

0 commit comments

Comments
 (0)