diff options
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.kts | 61 |
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 @@ | |||
1 | package tools.refinery.gradle | ||
2 | |||
3 | import org.gradle.accessors.dm.LibrariesForLibs | ||
4 | import tools.refinery.gradle.utils.EclipseUtils | ||
5 | import tools.refinery.gradle.utils.SonarPropertiesUtils | ||
6 | |||
7 | plugins { | ||
8 | id("tools.refinery.gradle.internal.java-conventions") | ||
9 | id("tools.refinery.gradle.sonarqube") | ||
10 | } | ||
11 | |||
12 | val sourceSets = the<SourceSetContainer>() | ||
13 | |||
14 | val 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 | |||
22 | val jmhImplementation: Configuration by configurations.getting { | ||
23 | extendsFrom(configurations.implementation.get(), configurations.testImplementation.get()) | ||
24 | } | ||
25 | |||
26 | val jmhAnnotationProcessor: Configuration by configurations.getting | ||
27 | |||
28 | configurations["jmhRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get(), configurations.testRuntimeOnly.get()) | ||
29 | |||
30 | val libs = the<LibrariesForLibs>() | ||
31 | |||
32 | dependencies { | ||
33 | jmhImplementation(libs.jmh.core) | ||
34 | jmhAnnotationProcessor(libs.jmh.annprocess) | ||
35 | } | ||
36 | |||
37 | tasks.register<JavaExec>("jmh") { | ||
38 | dependsOn(tasks.named("jmhClasses")) | ||
39 | mainClass.set("org.openjdk.jmh.Main") | ||
40 | classpath = jmh.runtimeClasspath | ||
41 | } | ||
42 | |||
43 | EclipseUtils.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 | |||
59 | sonarqube.properties { | ||
60 | SonarPropertiesUtils.addToList(properties, "sonar.tests", "src/jmh/java") | ||
61 | } | ||