Skip to content

Commit

Permalink
build(Gradle): Use conventions to opt-in to `ExperimentalSerializatio…
Browse files Browse the repository at this point in the history
…nApi`

This reduces code duplication and bundles `-opt-in` arguments.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Feb 20, 2024
1 parent 5457ed0 commit 15b4ee1
Show file tree
Hide file tree
Showing 21 changed files with 8 additions and 245 deletions.
13 changes: 8 additions & 5 deletions buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,14 @@ tasks.withType<JavaCompile>().configureEach {
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlin.contracts.ExperimentalContracts",
"-opt-in=kotlin.io.path.ExperimentalPathApi",
"-opt-in=kotlin.time.ExperimentalTime"
)
val hasSerialization = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId)

val customCompilerArgs = buildList {
add("-opt-in=kotlin.contracts.ExperimentalContracts")
add("-opt-in=kotlin.io.path.ExperimentalPathApi")
add("-opt-in=kotlin.time.ExperimentalTime")
if (hasSerialization) add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
}

compilerOptions {
allWarningsAsErrors = true
Expand Down
12 changes: 0 additions & 12 deletions clients/clearly-defined/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -36,13 +34,3 @@ dependencies {
implementation(libs.retrofit.converter.kotlinxSerialization)
implementation(libs.retrofit.converter.scalars)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/nexus-iq/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -34,13 +32,3 @@ dependencies {
implementation(libs.bundles.kotlinxSerialization)
implementation(libs.retrofit.converter.kotlinxSerialization)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/osv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -37,13 +35,3 @@ dependencies {

testImplementation(libs.kotest.assertions.json)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/scanoss/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -36,13 +34,3 @@ dependencies {

testImplementation(libs.wiremock)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/vulnerable-code/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -34,13 +32,3 @@ dependencies {
implementation(libs.bundles.kotlinxSerialization)
implementation(libs.retrofit.converter.kotlinxSerialization)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions evaluator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import de.undercouch.gradle.tasks.download.Download

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -45,16 +43,6 @@ dependencies {
testImplementation(libs.mockk)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}

tasks.register<Download>("updateOsadlMatrix") {
description = "Download the OSADL matrix in JSON format and add it as a resource."
group = "OSADL"
Expand Down
12 changes: 0 additions & 12 deletions plugins/advisors/osv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -35,13 +33,3 @@ dependencies {
implementation(libs.cvssCalculator)
implementation(libs.bundles.kotlinxSerialization)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/cargo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand Down Expand Up @@ -47,13 +45,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/go/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand Down Expand Up @@ -47,13 +45,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/nuget/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -41,13 +39,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/python/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand Down Expand Up @@ -46,13 +44,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/swiftpm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand Down Expand Up @@ -46,13 +44,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/reporters/ctrlx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -38,13 +36,3 @@ dependencies {

funTestImplementation(testFixtures(projects.reporter))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/reporters/gitlab/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -37,13 +35,3 @@ dependencies {

implementation(libs.bundles.kotlinxSerialization)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/reporters/trustsource/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -42,13 +40,3 @@ dependencies {

funTestImplementation(libs.kotest.assertions.json)
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/scanners/askalono/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -35,13 +33,3 @@ dependencies {

funTestApi(testFixtures(projects.scanner))
}

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

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
Loading

0 comments on commit 15b4ee1

Please sign in to comment.