diff options
Diffstat (limited to 'buildSrc/src/main/kotlin/refinery-java-test-fixtures.gradle.kts')
-rw-r--r-- | buildSrc/src/main/kotlin/refinery-java-test-fixtures.gradle.kts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/buildSrc/src/main/kotlin/refinery-java-test-fixtures.gradle.kts b/buildSrc/src/main/kotlin/refinery-java-test-fixtures.gradle.kts new file mode 100644 index 00000000..86b0a04b --- /dev/null +++ b/buildSrc/src/main/kotlin/refinery-java-test-fixtures.gradle.kts | |||
@@ -0,0 +1,31 @@ | |||
1 | import org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry | ||
2 | import org.gradle.plugins.ide.eclipse.model.EclipseModel | ||
3 | import tools.refinery.buildsrc.EclipseUtils | ||
4 | |||
5 | plugins { | ||
6 | `java-test-fixtures` | ||
7 | } | ||
8 | |||
9 | apply(plugin = "refinery-java-conventions") | ||
10 | |||
11 | the<EclipseModel>().classpath { | ||
12 | containsTestFixtures.set(true) | ||
13 | |||
14 | EclipseUtils.whenClasspathFileMerged(file) { eclipseClasspath -> | ||
15 | val hasTest = eclipseClasspath.entries.any { entry -> | ||
16 | entry is AbstractClasspathEntry && entry.entryAttributes["gradle_scope"] == "test" | ||
17 | } | ||
18 | EclipseUtils.patchClasspathEntries(eclipseClasspath) { entry -> | ||
19 | // Workaround https://github.com/gradle/gradle/issues/11845 based on | ||
20 | // https://discuss.gradle.org/t/gradle-used-by-scope-not-correctly-generated-when-the-java-test-fixtures-plugin-is-used/39935/2 | ||
21 | EclipseUtils.patchGradleUsedByScope(entry) { usedBy -> | ||
22 | if (usedBy.contains("main")) { | ||
23 | usedBy += "testFixtures" | ||
24 | } | ||
25 | if (hasTest && usedBy.contains("testFixtures")) { | ||
26 | usedBy += "test" | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | } | ||