Skip to content

Commit 475fc8a

Browse files
Fix opt-in usage error shown in IntelliJ IDEA for some of the project files (#4160)
* Use kotlin extension-level DSL for global args and opt-ins Applying free compiler arguments and opt-ins only to compilations leaves source sets that don't have any compilations misconfigured in the IDE. This includes shared test source sets and the special jdk8 source set. KGP 2.0.0 introduces an extension-level DSL that sets defaults for all source sets and provides a way to configure them properly. The arguments in the compilation conventions were kept. The pure JVM compilations still need the arguments, but they are not affected by the new multiplatform extension DSL. See https://youtrack.jetbrains.com/issue/KT-68642
1 parent 81ab2e7 commit 475fc8a

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
2+
3+
internal fun KotlinCommonCompilerOptions.configureGlobalKotlinArgumentsAndOptIns() {
4+
freeCompilerArgs.addAll("-progressive")
5+
optIn.addAll(
6+
"kotlin.experimental.ExperimentalTypeInference",
7+
// our own opt-ins that we don't want to bother with in our own code:
8+
"kotlinx.coroutines.DelicateCoroutinesApi",
9+
"kotlinx.coroutines.ExperimentalCoroutinesApi",
10+
"kotlinx.coroutines.ObsoleteCoroutinesApi",
11+
"kotlinx.coroutines.InternalCoroutinesApi",
12+
"kotlinx.coroutines.FlowPreview"
13+
)
14+
}

buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import org.jetbrains.kotlin.gradle.dsl.*
2-
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
31
import org.jetbrains.kotlin.gradle.tasks.*
4-
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
52

63
configure(subprojects) {
74
val project = this
@@ -39,17 +36,6 @@ configure(subprojects) {
3936
"kotlin.experimental.ExperimentalNativeApi",
4037
)
4138
}
42-
freeCompilerArgs.addAll("-progressive", "-Xexpect-actual-classes")
43-
optIn.addAll(
44-
"kotlin.experimental.ExperimentalTypeInference",
45-
"kotlin.ExperimentalMultiplatform",
46-
// our own opt-ins that we don't want to bother with in our own code:
47-
"kotlinx.coroutines.DelicateCoroutinesApi",
48-
"kotlinx.coroutines.ExperimentalCoroutinesApi",
49-
"kotlinx.coroutines.ObsoleteCoroutinesApi",
50-
"kotlinx.coroutines.InternalCoroutinesApi",
51-
"kotlinx.coroutines.FlowPreview"
52-
)
5339
}
5440

5541
}

buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ java {
1515
kotlin {
1616
compilerOptions {
1717
jvmTarget = JvmTarget.JVM_1_8
18+
configureGlobalKotlinArgumentsAndOptIns()
1819
}
1920
jvmToolchain(jdkToolchainVersion)
2021
}

buildSrc/src/main/kotlin/kotlin-multiplatform-conventions.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ kotlin {
123123
groupSourceSets("jsAndWasmJsShared", listOf("js", "wasmJs"), emptyList())
124124
groupSourceSets("jsAndWasmShared", listOf("jsAndWasmJsShared", "wasmWasi"), listOf("common"))
125125
}
126+
127+
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
128+
compilerOptions {
129+
configureGlobalKotlinArgumentsAndOptIns()
130+
freeCompilerArgs.add("-Xexpect-actual-classes")
131+
optIn.add("kotlin.ExperimentalMultiplatform")
132+
}
126133
}
127134

128135
// Disable intermediate sourceSet compilation because we do not need js-wasm common artifact

0 commit comments

Comments
 (0)