forked from battery-staple/KMeasure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
199 lines (170 loc) · 5.44 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
plugins {
kotlin("multiplatform") version "1.9.22"
`maven-publish`
signing
id("org.jetbrains.kotlinx.benchmark") version "0.4.9"
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.22"
}
group = "io.github.battery-staple"
version = "1.4.1"
repositories {
mavenCentral()
}
val environment: MutableMap<String, String> = System.getenv() ?: error("Could not get environment")
afterEvaluate {
extensions.findByType<PublishingExtension>()?.apply {
repositories {
maven {
url = uri(
if (isReleaseBuild) {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
)
credentials {
username = environment["sonatypeUsername"].toString()
password = environment["sonatypePassword"].toString()
}
}
}
publications.withType<MavenPublication>().configureEach {
artifact(emptyJavadocJar.get())
pom {
name.set("KMeasure")
description.set("A low-overhead library adding units to Kotlin Multiplatform")
url.set("https://github.com/battery-staple/KMeasure")
developers {
developer {
name.set("Rohen Giralt")
email.set("[email protected]")
organization {
name.set("None")
url.set("https://github.com/battery-staple/")
}
}
}
licenses {
license {
name.set("MIT License")
url.set("https://www.opensource.org/licenses/mit-license.php")
distribution.set("repo")
}
}
scm {
url.set("https://github.com/battery-staple/KMeasure")
}
}
}
}
extensions.findByType<SigningExtension>()?.apply {
val publishing = extensions.findByType<PublishingExtension>() ?: return@apply
val key = environment["signingKey"]?.replace("\\n", "\n")
val password = environment["signingPassword"]
useInMemoryPgpKeys(key, password)
sign(publishing.publications)
}
tasks.withType<Sign>().configureEach {
onlyIf { isReleaseBuild }
}
}
kotlin {
jvm {
compilations {
create("benchmark") { associateWith(compilations["main"]) }
all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
testRuns["test"].executionTask.configure {
useJUnit()
}
}
js {
browser {
commonWebpackConfig {
cssSupport {
enabled.set(true)
}
}
}
nodejs()
}
if (HostManager.host == KonanTarget.MACOS_X64) macosX64("native")
if (HostManager.host == KonanTarget.MACOS_ARM64) macosArm64("native")
if (HostManager.hostIsLinux) linuxX64("native")
if (HostManager.hostIsMingw) mingwX64("native")
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jvmBenchmark by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.9")
}
}
val jsMain by getting
val jsTest by getting
val nativeMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.9")
}
}
val nativeTest by getting
}
targets.all {
compilations.all {
kotlinOptions {
freeCompilerArgs += "-Xallow-kotlin-package"
}
}
}
}
// region Benchmarking config
allOpen {
annotation("org.openjdk.jmh.annotations.State")
}
benchmark {
configurations {
named("main") {
iterations = 5
iterationTime = 5
iterationTimeUnit = "sec"
advanced("jvmForks", "definedByJmh")
advanced("jsUseBridge", true)
advanced("nativeGCAfterIteration", true)
}
}
targets {
register("jvmBenchmark") {
this as JvmBenchmarkTarget
jmhVersion = "1.37"
}
register("js")
register("native")
}
}
// endregion
val emptyJavadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
val isReleaseBuild: Boolean
get() = !(version as String).endsWith("SNAPSHOT")
//region Fix Gradle warning about signing tasks using publishing task outputs without explicit dependencies
// https://github.com/gradle/gradle/issues/26091
// by aSemy on GitHub
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
//endregion