Skip to content

Commit 550e1a8

Browse files
authored
Rework opt-ins in build scripts (#2794)
* Move opt-in configurations from AbstractKotlinCompile compiler flags because AbstractKotlinCompile is a base type only for JVM & JS compilations, so this way of configuration is incorrect. Furthermore, we should not opt-in for every module in the project. Corresponding opt-ins were moved to projects' build scripts where appropriate. * Mark-up documentation with @ExperimentalSerializationApi where needed becuase :guide project does not have global opt-in into it. * Add @ExperimentalSerializationApi to @KeepGeneratedSerializer because this is a new feature.
1 parent 62aa4bb commit 550e1a8

40 files changed

+196
-36
lines changed

Diff for: build.gradle.kts

+3-17
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configur
9494

9595
subprojects {
9696
tasks.withType<org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile<*>>().configureEach {
97-
if (name.contains("Test") || name.contains("Jmh")) {
98-
compilerOptions.freeCompilerArgs.addAll(experimentalsInTestEnabled)
99-
} else {
100-
compilerOptions.freeCompilerArgs.addAll(experimentalsEnabled)
101-
}
97+
compilerOptions.freeCompilerArgs.addAll(globalCompilerArgs)
10298
}
10399
}
104100

@@ -172,18 +168,8 @@ gradle.taskGraph.whenReady {
172168
// getters are required because of variable lazy initialization in Gradle
173169
val unpublishedProjects get() = setOf("benchmark", "guide", "kotlinx-serialization-json-tests")
174170
val excludedFromBomProjects get() = unpublishedProjects + "kotlinx-serialization-bom"
175-
val experimentalsEnabled get() = listOf(
176-
"-progressive",
177-
"-opt-in=kotlin.ExperimentalMultiplatform",
178-
"-opt-in=kotlinx.serialization.InternalSerializationApi",
179-
"-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
180-
)
181-
182-
val experimentalsInTestEnabled get() = listOf(
183-
"-progressive",
184-
"-opt-in=kotlin.ExperimentalMultiplatform",
185-
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
186-
"-opt-in=kotlinx.serialization.InternalSerializationApi",
171+
val globalCompilerArgs
172+
get() = listOf(
187173
"-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
188174
)
189175

Diff for: core/commonMain/src/kotlinx/serialization/Annotations.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ public annotation class Polymorphic
341341
* Annotation is not allowed on classes involved in polymorphic serialization:
342342
* interfaces, sealed classes, abstract classes, classes marked by [Polymorphic].
343343
*
344-
* A compiler version `2.0.20` and higher is required.
344+
* A compiler version `2.0.20` or higher is required.
345345
*/
346+
@ExperimentalSerializationApi
346347
@Target(AnnotationTarget.CLASS)
347348
@Retention(AnnotationRetention.RUNTIME)
348349
public annotation class KeepGeneratedSerializer

Diff for: docs/basic-serialization.md

+2
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ For that purposes, [EncodeDefault] annotation can be used:
450450

451451
```kotlin
452452
@Serializable
453+
@OptIn(ExperimentalSerializationApi::class) // EncodeDefault is an experimental annotation for now
453454
data class Project(
454455
val name: String,
455456
@EncodeDefault val language: String = "Kotlin"
@@ -462,6 +463,7 @@ It's also possible to tweak it into the opposite behavior using [EncodeDefault.M
462463
```kotlin
463464

464465
@Serializable
466+
@OptIn(ExperimentalSerializationApi::class) // EncodeDefault is an experimental annotation for now
465467
data class User(
466468
val name: String,
467469
@EncodeDefault(EncodeDefault.Mode.NEVER) val projects: List<Project> = emptyList()

0 commit comments

Comments
 (0)