aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-07-28 12:29:05 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-07-28 12:29:05 +0200
commit94a1e92b5057dccbae582d34592486d4fa74e537 (patch)
treeb6af942707a4992dd2a6a72019715b4116680134 /buildSrc
parentchore: bump dependencies (diff)
downloadrefinery-94a1e92b5057dccbae582d34592486d4fa74e537.tar.gz
refinery-94a1e92b5057dccbae582d34592486d4fa74e537.tar.zst
refinery-94a1e92b5057dccbae582d34592486d4fa74e537.zip
build: fix testFixtures classpath in eclipse
Diffstat (limited to 'buildSrc')
-rw-r--r--buildSrc/src/main/groovy/refinery-java-conventions.gradle7
-rw-r--r--buildSrc/src/main/groovy/refinery-java-test-fixtures.gradle31
-rw-r--r--buildSrc/src/main/groovy/refinery-jmh.gradle28
3 files changed, 53 insertions, 13 deletions
diff --git a/buildSrc/src/main/groovy/refinery-java-conventions.gradle b/buildSrc/src/main/groovy/refinery-java-conventions.gradle
index b2efd7e9..5bc73f61 100644
--- a/buildSrc/src/main/groovy/refinery-java-conventions.gradle
+++ b/buildSrc/src/main/groovy/refinery-java-conventions.gradle
@@ -69,6 +69,13 @@ eclipse {
69 if (entry.path.endsWith('-gen')) { 69 if (entry.path.endsWith('-gen')) {
70 entry.entryAttributes['ignore_optional_problems'] = true 70 entry.entryAttributes['ignore_optional_problems'] = true
71 } 71 }
72 // If a project has a main dependency on a project and an test dependency on the testFixtures of a project,
73 // it will be errorneously added as a test-only dependency to Eclipse.
74 // As a workaround, we add all project dependencies as main dependencies
75 // (we do not deliberately use test-only project dependencies).
76 if (entry in org.gradle.plugins.ide.eclipse.model.ProjectDependency) {
77 entry.entryAttributes.remove('test')
78 }
72 } 79 }
73 } 80 }
74 81
diff --git a/buildSrc/src/main/groovy/refinery-java-test-fixtures.gradle b/buildSrc/src/main/groovy/refinery-java-test-fixtures.gradle
new file mode 100644
index 00000000..326fa868
--- /dev/null
+++ b/buildSrc/src/main/groovy/refinery-java-test-fixtures.gradle
@@ -0,0 +1,31 @@
1plugins {
2 id 'java-test-fixtures'
3 id 'refinery-java-conventions'
4}
5
6eclipse.classpath {
7 containsTestFixtures = true
8
9 file.whenMerged { classpath ->
10 def hasTest = classpath.entries.any { entry ->
11 entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry &&
12 entry.entryAttributes['gradle_scope'] == 'test'
13 }
14 for (entry in classpath.entries) {
15 // Workaround https://github.com/gradle/gradle/issues/11845 based on
16 // https://discuss.gradle.org/t/gradle-used-by-scope-not-correctly-generated-when-the-java-test-fixtures-plugin-is-used/39935/2
17 if (entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) {
18 def usedBy = new LinkedHashSet(
19 Arrays.asList((entry.entryAttributes['gradle_used_by_scope'] ?: '').split(','))
20 )
21 if (usedBy.contains('main')) {
22 usedBy += 'testFixtures'
23 }
24 if (hasTest && usedBy.contains('testFixtures')) {
25 usedBy += 'test'
26 }
27 entry.entryAttributes['gradle_used_by_scope'] = usedBy.join(',')
28 }
29 }
30 }
31}
diff --git a/buildSrc/src/main/groovy/refinery-jmh.gradle b/buildSrc/src/main/groovy/refinery-jmh.gradle
index 48e0c133..17654463 100644
--- a/buildSrc/src/main/groovy/refinery-jmh.gradle
+++ b/buildSrc/src/main/groovy/refinery-jmh.gradle
@@ -29,23 +29,25 @@ tasks.register('jmh', JavaExec) {
29 classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath 29 classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath
30} 30}
31 31
32eclipse.classpath { 32eclipse.classpath.file.whenMerged { classpath ->
33 plusConfigurations += [configurations.jmhCompileClasspath, configurations.jmhRuntimeClasspath] 33 for (entry in classpath.entries) {
34 34 if (entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) {
35 file.whenMerged { classpath ->
36 for (entry in classpath.entries) {
37 // Workaround from https://github.com/gradle/gradle/issues/4802#issuecomment-407902081 35 // Workaround from https://github.com/gradle/gradle/issues/4802#issuecomment-407902081
38 if (entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) { 36 if (entry.entryAttributes['gradle_scope'] == 'jmh') {
39 def usedBy = (entry.entryAttributes['gradle_used_by_scope'] ?: '').split(',') 37 // Allow test helper classes to be used in benchmarks from Eclipse
40 if (usedBy == ['jmh']) { 38 // and do not expose JMH dependencies to the main source code.
41 // Allow test helper classes to be used in benchmarks from Eclipse 39 entry.entryAttributes['test'] = true
42 // and do not expose JMH dependencies to the main source code. 40 } else {
43 entry.entryAttributes['test'] = true 41 // Workaround based on
44 } else if ((usedBy.contains('main') || usedBy.contains('test')) && !usedBy.contains('jmh')) { 42 // https://discuss.gradle.org/t/gradle-used-by-scope-not-correctly-generated-when-the-java-test-fixtures-plugin-is-used/39935/2
43 def usedBy = new LinkedHashSet(
44 Arrays.asList((entry.entryAttributes['gradle_used_by_scope'] ?: '').split(','))
45 )
46 if (['main', 'test', 'testFixtures'].any { e -> usedBy.contains(e) }) {
45 // main and test sources are also used by jmh sources. 47 // main and test sources are also used by jmh sources.
46 usedBy += 'jmh' 48 usedBy += 'jmh'
47 entry.entryAttributes['gradle_used_by_scope'] = usedBy.join(',')
48 } 49 }
50 entry.entryAttributes['gradle_used_by_scope'] = usedBy.join(',')
49 } 51 }
50 } 52 }
51 } 53 }