Skip to content

Commit 2b9a587

Browse files
authored
Use reflective access for JavaModuleDetector methods (#173)
1 parent 3483edb commit 2b9a587

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Java Module Testing Gradle Plugin - Changelog
22

3+
## Version 1.8.1
4+
* [#172](https://github.com/gradlex-org/java-module-testing/issues/172) Fix incompatibility with Gradle 9.5.0+
5+
36
## Version 1.8
47
* [#143](https://github.com/gradlex-org/java-module-testing/issues/143) Fully support other source sets than 'main' in whitebox tests
58
* [#114](https://github.com/gradlex-org/java-module-testing/issues/114) Fix: issue where the plugin causes a 'mutating a configuration after it has been resolved' error

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ publishingConventions {
1515
}
1616
}
1717

18-
testingConventions { testGradleVersions("7.4", "7.6.5", "8.0.2", "8.14.2") }
18+
// 9.4.1 is the last version where 'JavaModuleDetector' is a class and not an interface
19+
testingConventions { testGradleVersions("7.4", "7.6.5", "8.0.2", "8.14.2", "9.4.1") }

src/main/java/org/gradlex/javamodule/testing/internal/actions/JavaCompileSetModulePathAction.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package org.gradlex.javamodule.testing.internal.actions;
33

4+
import java.lang.reflect.Method;
45
import java.util.ArrayList;
56
import java.util.List;
67
import javax.inject.Inject;
@@ -31,10 +32,22 @@ public void execute(Task task) {
3132

3233
// Since for Gradle this sources set does not look like a module, we have to define the module path ourselves
3334
compilerArgs.add("--module-path");
34-
compilerArgs.add(getJavaModuleDetector()
35-
.inferModulePath(true, classpathAndModulePath)
36-
.getAsPath());
37-
javaCompile.setClasspath(getJavaModuleDetector().inferClasspath(true, classpathAndModulePath));
35+
compilerArgs.add(infer("ModulePath", classpathAndModulePath).getAsPath());
36+
javaCompile.setClasspath(infer("Classpath", classpathAndModulePath));
3837
javaCompile.getOptions().setCompilerArgs(compilerArgs);
3938
}
39+
40+
/**
41+
* Use reflective access for JavaModuleDetector methods so that it does not matter if JavaModuleDetector is a
42+
* class (<9.5.0) or an interface (9.5.0+).
43+
*/
44+
private FileCollection infer(String pathType, FileCollection classpathAndModulePath) {
45+
try {
46+
Method inferModulePath =
47+
JavaModuleDetector.class.getDeclaredMethod("infer" + pathType, boolean.class, FileCollection.class);
48+
return (FileCollection) inferModulePath.invoke(getJavaModuleDetector(), true, classpathAndModulePath);
49+
} catch (ReflectiveOperationException e) {
50+
throw new RuntimeException(e);
51+
}
52+
}
4053
}

0 commit comments

Comments
 (0)