Skip to content

Commit c49fdf9

Browse files
committed
build(gradle): Use the dedicated optIn DSL for Kotlin compiler options
Refactor the code a little bit along the way. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent f804dd0 commit c49fdf9

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ tasks.withType<Detekt>().configureEach detekt@{
161161
}
162162

163163
tasks.withType<KotlinCompile>().configureEach {
164-
val hasSerialization = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId)
165-
166-
val customCompilerArgs = buildList {
167-
add("-opt-in=kotlin.contracts.ExperimentalContracts")
168-
add("-opt-in=kotlin.io.encoding.ExperimentalEncodingApi")
169-
add("-opt-in=kotlin.io.path.ExperimentalPathApi")
170-
add("-opt-in=kotlin.time.ExperimentalTime")
171-
if (hasSerialization) add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
172-
}
164+
val hasSerializationPlugin = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId)
165+
166+
val optInRequirements = listOfNotNull(
167+
"kotlin.contracts.ExperimentalContracts",
168+
"kotlin.io.encoding.ExperimentalEncodingApi",
169+
"kotlin.io.path.ExperimentalPathApi",
170+
"kotlin.time.ExperimentalTime",
171+
"kotlinx.serialization.ExperimentalSerializationApi".takeIf { hasSerializationPlugin }
172+
)
173173

174174
compilerOptions {
175175
allWarningsAsErrors = true
176-
freeCompilerArgs.addAll(customCompilerArgs)
176+
optIn = optInRequirements
177177
jvmTarget = maxKotlinJvmTarget
178178
}
179179
}

plugins/scanners/scanoss/build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ dependencies {
4343
}
4444

4545
tasks.named<KotlinCompile>("compileTestKotlin") {
46-
val customCompilerArgs = listOf(
47-
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
48-
)
49-
5046
compilerOptions {
51-
freeCompilerArgs.addAll(customCompilerArgs)
47+
optIn = listOf("kotlinx.serialization.ExperimentalSerializationApi")
5248
}
5349
}

0 commit comments

Comments
 (0)