diff options
Diffstat (limited to 'buildSrc/src/main/groovy/refinery-jmh.gradle')
-rw-r--r-- | buildSrc/src/main/groovy/refinery-jmh.gradle | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/buildSrc/src/main/groovy/refinery-jmh.gradle b/buildSrc/src/main/groovy/refinery-jmh.gradle new file mode 100644 index 00000000..553c469b --- /dev/null +++ b/buildSrc/src/main/groovy/refinery-jmh.gradle | |||
@@ -0,0 +1,58 @@ | |||
1 | plugins { | ||
2 | id 'org.sonarqube' | ||
3 | id 'refinery-java-conventions' | ||
4 | } | ||
5 | |||
6 | configurations { | ||
7 | jmh { | ||
8 | extendsFrom implementation | ||
9 | } | ||
10 | } | ||
11 | |||
12 | sourceSets { | ||
13 | jmh { | ||
14 | java.srcDirs = ['src/jmh/java'] | ||
15 | resources.srcDirs = ['src/jmh/resources'] | ||
16 | compileClasspath += sourceSets.main.runtimeClasspath | ||
17 | compileClasspath += sourceSets.test.runtimeClasspath | ||
18 | } | ||
19 | } | ||
20 | |||
21 | dependencies { | ||
22 | jmhImplementation libs.jmh.core | ||
23 | jmhAnnotationProcessor libs.jmh.annprocess | ||
24 | } | ||
25 | |||
26 | tasks.register('jmh', JavaExec) { | ||
27 | dependsOn tasks.named('jmhClasses') | ||
28 | main = 'org.openjdk.jmh.Main' | ||
29 | classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath | ||
30 | } | ||
31 | |||
32 | eclipse.classpath { | ||
33 | plusConfigurations += [configurations.jmhCompileClasspath, configurations.jmhRuntimeClasspath] | ||
34 | |||
35 | file.whenMerged { classpath -> | ||
36 | for (entry in classpath.entries) { | ||
37 | // Workaround from https://github.com/gradle/gradle/issues/4802#issuecomment-407902081 | ||
38 | if (entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) { | ||
39 | def usedBy = (entry.entryAttributes['gradle_used_by_scope'] ?: '').split(',') | ||
40 | if (usedBy == ['jmh']) { | ||
41 | // Allow test helper classes to be used in benchmarks from Eclipse | ||
42 | // and do not expose JMH dependencies to the main source code. | ||
43 | entry.entryAttributes['test'] = true | ||
44 | } else if ((usedBy.contains('main') || usedBy.contains('test')) && !usedBy.contains('jmh')) { | ||
45 | // main and test sources are also used by jmh sources. | ||
46 | usedBy += 'jmh' | ||
47 | entry.entryAttributes['gradle_used_by_scope'] = usedBy.join(',') | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | sonarqube.properties { | ||
55 | properties['sonar.tests'] += [ | ||
56 | 'src/jmh/java', | ||
57 | ] | ||
58 | } | ||