@@ -10,8 +10,11 @@ import com.squareup.workflow1.buildsrc.internal.javaTargetInt
1010import com.squareup.workflow1.buildsrc.internal.kotlin
1111import org.gradle.api.Project
1212import org.gradle.api.tasks.compile.JavaCompile
13+ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Strict
14+ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1315import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
1416import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
17+ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
1518
1619fun Project.kotlinCommonSettings (bomConfigurationName : String ) {
1720 pluginManager.apply (libsCatalog.pluginId(" ktlint" ))
@@ -28,39 +31,31 @@ fun Project.kotlinCommonSettings(bomConfigurationName: String) {
2831 }
2932
3033 tasks.withType(KotlinCompile ::class .java).configureEach { kotlinCompile ->
31- kotlinCompile.kotlinOptions {
32- jvmTarget = this @kotlinCommonSettings.javaTarget
34+ kotlinCompile.apply {
35+ if (! (path.startsWith(" :samples" ) || path.startsWith(" :benchmarks" ) ||
36+ name.contains(" test" , ignoreCase = true ))
37+ ) {
38+ explicitApiMode.set(Strict )
39+ }
40+ }
41+ kotlinCompile.compilerOptions {
42+ jvmTarget.set(JvmTarget .fromTarget(this @kotlinCommonSettings.javaTarget))
3343
3444 // Allow warnings when running from IDE, makes it easier to experiment.
3545 if (! isRunningFromIde) {
36- allWarningsAsErrors = true
46+ allWarningsAsErrors.set( true )
3747 }
3848
3949 // Don't panic, all this does is allow us to use the @OptIn meta-annotation.
4050 // to define our own experiments.
41- freeCompilerArgs + = " -opt-in=kotlin.RequiresOptIn"
51+ freeCompilerArgs.add( " -opt-in=kotlin.RequiresOptIn" )
4252
4353 // Make sure our module names don't conflict with those from pre-workflow1
4454 // releases, so that old and new META-INF/ entries don't stomp each other.
4555 // (This is only an issue for apps that are still migrating from workflow to
4656 // workflow1, and so need to import two versions of the library.)
4757 // https://blog.jetbrains.com/kotlin/2015/09/kotlin-m13-is-out/
48- moduleName = " wf1-${project.name} "
49- }
50-
51- maybeEnableExplicitApi(kotlinCompile)
52- }
53- }
54-
55- private fun Project.maybeEnableExplicitApi (compileTask : KotlinCompile ) {
56- when {
57- path.startsWith(" :samples" ) -> return
58- path.startsWith(" :benchmarks" ) -> return
59- compileTask.name.contains(" test" , ignoreCase = true ) -> return
60- else -> compileTask.kotlinOptions {
61- // TODO this should be moved to `kotlin { explicitApi() }` once that's working for android
62- // projects, see https://youtrack.jetbrains.com/issue/KT-37652.
63- freeCompilerArgs + = " -Xexplicit-api=strict"
58+ moduleName.set(" wf1-${project.name} " )
6459 }
6560 }
6661}
0 commit comments