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