Skip to content

Commit

Permalink
Fix explicit API mode in KMP projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Mar 1, 2024
1 parent c388417 commit 4f68805
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.github.reactivecircus.kstreamlined.buildlogic

import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/**
* Apply common configs to KMP project.
Expand Down Expand Up @@ -50,23 +50,16 @@ internal fun KotlinMultiplatformExtension.configureKMPTest() {
}

/**
* Configure Kotlin common compile options.
* Configure Kotlin compile options.
*/
internal fun Project.configureKotlinCommonCompileOptions() {
tasks.withType<KotlinCommonCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + commonCompilerArgs
}
}
}

/**
* Enable explicit API mode for non-test Kotlin compilations
*/
internal fun Project.enableExplicitApi() {
tasks.withType<KotlinCommonCompile>().configureEach {
if (!name.contains("TestKotlin")) {
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict"
internal fun Project.configureKotlinCompileOptions() {
tasks.withType<KotlinCompile>().configureEach {
with(compilerOptions.freeCompilerArgs) {
addAll(commonCompilerArgs)
// enable explicit API mode for non-test Kotlin compilations
if (!name.contains("TestKotlin")) {
add("-Xexplicit-api=strict")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package io.github.reactivecircus.kstreamlined.buildlogic.convention

import io.github.reactivecircus.kstreamlined.buildlogic.configureDetekt
import io.github.reactivecircus.kstreamlined.buildlogic.configureKMPCommon
import io.github.reactivecircus.kstreamlined.buildlogic.configureKotlinCommonCompileOptions
import io.github.reactivecircus.kstreamlined.buildlogic.configureKotlinCompileOptions
import io.github.reactivecircus.kstreamlined.buildlogic.configureTest
import io.github.reactivecircus.kstreamlined.buildlogic.enableExplicitApi
import io.github.reactivecircus.kstreamlined.buildlogic.markNonCompatibleConfigurationCacheTasks
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -17,10 +16,9 @@ internal class KMPCommonConventionPlugin : Plugin<Project> {

extensions.configure<KotlinMultiplatformExtension> {
configureKMPCommon(target)
enableExplicitApi()
}

configureKotlinCommonCompileOptions()
configureKotlinCompileOptions()
configureTest()
configureDetekt()
markNonCompatibleConfigurationCacheTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package io.github.reactivecircus.kstreamlined.buildlogic.convention

import io.github.reactivecircus.kstreamlined.buildlogic.configureDetekt
import io.github.reactivecircus.kstreamlined.buildlogic.configureKMPCommon
import io.github.reactivecircus.kstreamlined.buildlogic.configureKotlinCommonCompileOptions
import io.github.reactivecircus.kstreamlined.buildlogic.configureKotlinCompileOptions
import io.github.reactivecircus.kstreamlined.buildlogic.configureTest
import io.github.reactivecircus.kstreamlined.buildlogic.enableExplicitApi
import io.github.reactivecircus.kstreamlined.buildlogic.markNonCompatibleConfigurationCacheTasks
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -17,10 +16,9 @@ internal class KMPIosOnlyConventionPlugin : Plugin<Project> {

extensions.configure<KotlinMultiplatformExtension> {
configureKMPCommon(target, enableJvmTarget = false)
enableExplicitApi()
}

configureKotlinCommonCompileOptions()
configureKotlinCompileOptions()
configureTest()
configureDetekt()
markNonCompatibleConfigurationCacheTasks()
Expand Down

0 comments on commit 4f68805

Please sign in to comment.