aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc/src/main/kotlin/tools/refinery/gradle/jmh.gradle.kts
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc/src/main/kotlin/tools/refinery/gradle/jmh.gradle.kts')
-rw-r--r--buildSrc/src/main/kotlin/tools/refinery/gradle/jmh.gradle.kts61
1 files changed, 61 insertions, 0 deletions
diff --git a/buildSrc/src/main/kotlin/tools/refinery/gradle/jmh.gradle.kts b/buildSrc/src/main/kotlin/tools/refinery/gradle/jmh.gradle.kts
new file mode 100644
index 00000000..eda7d5c6
--- /dev/null
+++ b/buildSrc/src/main/kotlin/tools/refinery/gradle/jmh.gradle.kts
@@ -0,0 +1,61 @@
1package tools.refinery.gradle
2
3import org.gradle.accessors.dm.LibrariesForLibs
4import tools.refinery.gradle.utils.EclipseUtils
5import tools.refinery.gradle.utils.SonarPropertiesUtils
6
7plugins {
8 id("tools.refinery.gradle.internal.java-conventions")
9 id("tools.refinery.gradle.sonarqube")
10}
11
12val sourceSets = the<SourceSetContainer>()
13
14val jmh: SourceSet by sourceSets.creating {
15 compileClasspath += sourceSets.main.get().output
16 runtimeClasspath += sourceSets.main.get().output
17 // Allow using test classes in benchmarks for now.
18 compileClasspath += sourceSets.test.get().output
19 runtimeClasspath += sourceSets.test.get().output
20}
21
22val jmhImplementation: Configuration by configurations.getting {
23 extendsFrom(configurations.implementation.get(), configurations.testImplementation.get())
24}
25
26val jmhAnnotationProcessor: Configuration by configurations.getting
27
28configurations["jmhRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get(), configurations.testRuntimeOnly.get())
29
30val libs = the<LibrariesForLibs>()
31
32dependencies {
33 jmhImplementation(libs.jmh.core)
34 jmhAnnotationProcessor(libs.jmh.annprocess)
35}
36
37tasks.register<JavaExec>("jmh") {
38 dependsOn(tasks.named("jmhClasses"))
39 mainClass.set("org.openjdk.jmh.Main")
40 classpath = jmh.runtimeClasspath
41}
42
43EclipseUtils.patchClasspathEntries(eclipse) { entry ->
44 // Workaround from https://github.com/gradle/gradle/issues/4802#issuecomment-407902081
45 if (entry.entryAttributes["gradle_scope"] == "jmh") {
46 // Allow test helper classes to be used in benchmarks from Eclipse
47 // and do not expose JMH dependencies to the main source code.
48 entry.entryAttributes["test"] = true
49 } else {
50 EclipseUtils.patchGradleUsedByScope(entry) { usedBy ->
51 if (listOf("main", "test", "testFixtures").any { e -> usedBy.contains(e) }) {
52 // main and test sources are also used by jmh sources.
53 usedBy += "jmh"
54 }
55 }
56 }
57}
58
59sonarqube.properties {
60 SonarPropertiesUtils.addToList(properties, "sonar.tests", "src/jmh/java")
61}