diff options
author | 2023-04-08 22:56:44 +0200 | |
---|---|---|
committer | 2023-04-08 22:58:21 +0200 | |
commit | 561fac70fd3dc3ebe1cfbc50146757495fb828d5 (patch) | |
tree | 20aa72bbe438aaa70c8de264ff0d366758e7772d /buildSrc/src/main/kotlin/refinery-jmh.gradle.kts | |
parent | refactor: remove TupleLike (diff) | |
download | refinery-561fac70fd3dc3ebe1cfbc50146757495fb828d5.tar.gz refinery-561fac70fd3dc3ebe1cfbc50146757495fb828d5.tar.zst refinery-561fac70fd3dc3ebe1cfbc50146757495fb828d5.zip |
build: convert Gradle scripts to Kotlin
Improves IDE support build scripts in IntelliJ.
There is no Eclipse IDE support, but Eclipse didn't have support for Groovy
either, so there is no degradation of functionality.
Diffstat (limited to 'buildSrc/src/main/kotlin/refinery-jmh.gradle.kts')
-rw-r--r-- | buildSrc/src/main/kotlin/refinery-jmh.gradle.kts | 63 |
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 @@ | |||
1 | import org.gradle.accessors.dm.LibrariesForLibs | ||
2 | import org.gradle.plugins.ide.eclipse.model.EclipseModel | ||
3 | import org.sonarqube.gradle.SonarExtension | ||
4 | import tools.refinery.buildsrc.EclipseUtils | ||
5 | import tools.refinery.buildsrc.SonarPropertiesUtils | ||
6 | |||
7 | apply(plugin = "refinery-java-conventions") | ||
8 | apply(plugin = "refinery-sonarqube") | ||
9 | |||
10 | val sourceSets = the<SourceSetContainer>() | ||
11 | |||
12 | val main: SourceSet by sourceSets.getting | ||
13 | |||
14 | val test: SourceSet by sourceSets.getting | ||
15 | |||
16 | val 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 | |||
24 | val jmhImplementation: Configuration by configurations.getting { | ||
25 | extendsFrom(configurations["implementation"], configurations["testImplementation"]) | ||
26 | } | ||
27 | |||
28 | val jmhAnnotationProcessor: Configuration by configurations.getting | ||
29 | |||
30 | configurations["jmhRuntimeOnly"].extendsFrom(configurations["runtimeOnly"], configurations["testRuntimeOnly"]) | ||
31 | |||
32 | val libs = the<LibrariesForLibs>() | ||
33 | |||
34 | dependencies { | ||
35 | jmhImplementation(libs.jmh.core) | ||
36 | jmhAnnotationProcessor(libs.jmh.annprocess) | ||
37 | } | ||
38 | |||
39 | tasks.register("jmh", JavaExec::class) { | ||
40 | dependsOn(tasks.named("jmhClasses")) | ||
41 | mainClass.set("org.openjdk.jmh.Main") | ||
42 | classpath = jmh.runtimeClasspath | ||
43 | } | ||
44 | |||
45 | EclipseUtils.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 | |||
61 | the<SonarExtension>().properties { | ||
62 | SonarPropertiesUtils.addToList(properties, "sonar.tests", "src/jmh/java") | ||
63 | } | ||