Skip to content

Commit 0bcbeef

Browse files
committed
always add the Kotlin bom dependency, and only add it once
1 parent a0ed706 commit 0bcbeef

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

buildSrc/src/main/java/com/squareup/workflow1/buildsrc/KotlinCommonSettings.kt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.squareup.workflow1.buildsrc
33
import org.gradle.api.Project
44
import org.gradle.kotlin.dsl.dependencies
55
import org.gradle.kotlin.dsl.kotlin
6+
import org.gradle.kotlin.dsl.withType
67
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
78

89
// See https://stackoverflow.com/questions/25324880/detect-ide-environment-with-gradle
@@ -11,35 +12,38 @@ val Project.isRunningFromIde
1112

1213
@Suppress("SuspiciousCollectionReassignment")
1314
fun Project.kotlinCommonSettings(
14-
compileTask: KotlinCompile,
15-
configuration: String = "implementation",
15+
bomConfigurationName: String
1616
) {
1717

1818
// force the same Kotlin version everywhere, including transitive dependencies
1919
dependencies {
20-
configuration(platform(kotlin("bom")))
20+
bomConfigurationName(platform(kotlin("bom")))
2121
}
2222

23-
compileTask.kotlinOptions {
23+
tasks.withType<KotlinCompile> {
24+
kotlinOptions {
2425

25-
// Allow warnings when running from IDE, makes it easier to experiment.
26-
if (!isRunningFromIde) {
27-
allWarningsAsErrors = true
28-
}
26+
jvmTarget = "1.8"
2927

30-
// Don't panic, all this does is allow us to use the @OptIn meta-annotation.
31-
// to define our own experiments.
32-
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
28+
// Allow warnings when running from IDE, makes it easier to experiment.
29+
if (!isRunningFromIde) {
30+
allWarningsAsErrors = true
31+
}
3332

34-
// Make sure our module names don't conflict with those from pre-workflow1
35-
// releases, so that old and new META-INF/ entries don't stomp each other.
36-
// (This is only an issue for apps that are still migrating from workflow to
37-
// workflow1, and so need to import two versions of the library.)
38-
// https://blog.jetbrains.com/kotlin/2015/09/kotlin-m13-is-out/
39-
moduleName = "wf1-${project.name}"
40-
}
33+
// Don't panic, all this does is allow us to use the @OptIn meta-annotation.
34+
// to define our own experiments.
35+
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
4136

42-
maybeEnableExplicitApi(compileTask)
37+
// Make sure our module names don't conflict with those from pre-workflow1
38+
// releases, so that old and new META-INF/ entries don't stomp each other.
39+
// (This is only an issue for apps that are still migrating from workflow to
40+
// workflow1, and so need to import two versions of the library.)
41+
// https://blog.jetbrains.com/kotlin/2015/09/kotlin-m13-is-out/
42+
moduleName = "wf1-${project.name}"
43+
}
44+
45+
maybeEnableExplicitApi(this@withType)
46+
}
4347
}
4448

4549
private fun Project.maybeEnableExplicitApi(compileTask: KotlinCompile) {
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.squareup.workflow1.buildsrc.kotlinCommonSettings
2-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
32

43
plugins {
54
kotlin("android")
@@ -10,10 +9,4 @@ extensions.getByType(JavaPluginExtension::class).apply {
109
targetCompatibility = JavaVersion.VERSION_1_8
1110
}
1211

13-
tasks.withType<KotlinCompile> {
14-
kotlinOptions {
15-
jvmTarget = "1.8"
16-
}
17-
18-
project.kotlinCommonSettings(this)
19-
}
12+
project.kotlinCommonSettings(bomConfigurationName = "implementation")
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.squareup.workflow1.buildsrc.kotlinCommonSettings
2-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
32

43
plugins {
54
kotlin("jvm")
@@ -10,10 +9,4 @@ extensions.getByType(JavaPluginExtension::class).apply {
109
targetCompatibility = JavaVersion.VERSION_1_8
1110
}
1211

13-
tasks.withType<KotlinCompile> {
14-
kotlinOptions {
15-
jvmTarget = "1.8"
16-
}
17-
18-
project.kotlinCommonSettings(this)
19-
}
12+
project.kotlinCommonSettings(bomConfigurationName = "implementation")
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.squareup.workflow1.buildsrc.kotlinCommonSettings
2-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
32

43
plugins {
54
kotlin("multiplatform")
@@ -10,10 +9,4 @@ extensions.getByType(JavaPluginExtension::class).apply {
109
targetCompatibility = JavaVersion.VERSION_1_8
1110
}
1211

13-
tasks.withType<KotlinCompile> {
14-
kotlinOptions {
15-
jvmTarget = "1.8"
16-
}
17-
18-
project.kotlinCommonSettings(this, "commonMainImplementation")
19-
}
12+
project.kotlinCommonSettings(bomConfigurationName = "commonMainImplementation")

0 commit comments

Comments
 (0)