Skip to content

Commit 2e25b00

Browse files
sellmairqurbonzoda
authored andcommitted
Update 'examples/kotlin' build script
- convert the script to build.gradle.kts - Use associateWith over manually configuring dependencies
1 parent 6540e09 commit 2e25b00

File tree

2 files changed

+50
-53
lines changed

2 files changed

+50
-53
lines changed

examples/kotlin/build.gradle

Lines changed: 0 additions & 53 deletions
This file was deleted.

examples/kotlin/build.gradle.kts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
2+
3+
plugins {
4+
kotlin("jvm")
5+
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.21"
6+
id("org.jetbrains.kotlinx.benchmark")
7+
}
8+
9+
// how to apply plugin to a specific source set?
10+
allOpen {
11+
annotation("org.openjdk.jmh.annotations.State")
12+
}
13+
14+
sourceSets {
15+
create("benchmarks")
16+
}
17+
18+
sourceSets.configureEach {
19+
kotlin.setSrcDirs(listOf(file("$name/src")))
20+
java.setSrcDirs(listOf(file("$name/src")))
21+
resources.setSrcDirs(listOf(file("$name/resources")))
22+
}
23+
24+
kotlin {
25+
/*
26+
Associate the benchmarks with the main compilation.
27+
This will:
28+
1. Allow 'benchmarks' to see all internals of 'main'
29+
2. Forward all dependencies from 'main' to be also visible in 'benchmarks'
30+
*/
31+
target.compilations.getByName("benchmarks")
32+
.associateWith(target.compilations.getByName("main"))
33+
}
34+
35+
// Add dependency to the benchmark runtime
36+
dependencies {
37+
"benchmarksImplementation"(project(":kotlinx-benchmark-runtime"))
38+
}
39+
40+
41+
// Configure benchmark
42+
benchmark {
43+
targets {
44+
register("benchmarks") {
45+
if(this is JvmBenchmarkTarget) {
46+
jmhVersion = "1.21"
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)