Skip to content

Commit

Permalink
build(gradle): Use the dedicated optIn DSL for Kotlin compiler options
Browse files Browse the repository at this point in the history
Refactor the code a little bit along the way.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed May 8, 2024
1 parent f804dd0 commit c49fdf9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
20 changes: 10 additions & 10 deletions buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ tasks.withType<Detekt>().configureEach detekt@{
}

tasks.withType<KotlinCompile>().configureEach {
val hasSerialization = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId)

val customCompilerArgs = buildList {
add("-opt-in=kotlin.contracts.ExperimentalContracts")
add("-opt-in=kotlin.io.encoding.ExperimentalEncodingApi")
add("-opt-in=kotlin.io.path.ExperimentalPathApi")
add("-opt-in=kotlin.time.ExperimentalTime")
if (hasSerialization) add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
}
val hasSerializationPlugin = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId)

val optInRequirements = listOfNotNull(
"kotlin.contracts.ExperimentalContracts",
"kotlin.io.encoding.ExperimentalEncodingApi",
"kotlin.io.path.ExperimentalPathApi",
"kotlin.time.ExperimentalTime",
"kotlinx.serialization.ExperimentalSerializationApi".takeIf { hasSerializationPlugin }
)

compilerOptions {
allWarningsAsErrors = true
freeCompilerArgs.addAll(customCompilerArgs)
optIn = optInRequirements
jvmTarget = maxKotlinJvmTarget
}
}
Expand Down
6 changes: 1 addition & 5 deletions plugins/scanners/scanoss/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ dependencies {
}

tasks.named<KotlinCompile>("compileTestKotlin") {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
optIn = listOf("kotlinx.serialization.ExperimentalSerializationApi")
}
}

0 comments on commit c49fdf9

Please sign in to comment.