Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework opt-ins in build scripts #2794

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configur

subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile<*>>().configureEach {
if (name.contains("Test") || name.contains("Jmh")) {
compilerOptions.freeCompilerArgs.addAll(experimentalsInTestEnabled)
} else {
compilerOptions.freeCompilerArgs.addAll(experimentalsEnabled)
}
compilerOptions.freeCompilerArgs.addAll(globalCompilerArgs)
}
}

Expand Down Expand Up @@ -172,18 +168,8 @@ gradle.taskGraph.whenReady {
// getters are required because of variable lazy initialization in Gradle
val unpublishedProjects get() = setOf("benchmark", "guide", "kotlinx-serialization-json-tests")
val excludedFromBomProjects get() = unpublishedProjects + "kotlinx-serialization-bom"
val experimentalsEnabled get() = listOf(
"-progressive",
"-opt-in=kotlin.ExperimentalMultiplatform",
"-opt-in=kotlinx.serialization.InternalSerializationApi",
"-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
)

val experimentalsInTestEnabled get() = listOf(
"-progressive",
"-opt-in=kotlin.ExperimentalMultiplatform",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=kotlinx.serialization.InternalSerializationApi",
val globalCompilerArgs
get() = listOf(
"-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
)

Expand Down
3 changes: 2 additions & 1 deletion core/commonMain/src/kotlinx/serialization/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ public annotation class Polymorphic
* Annotation is not allowed on classes involved in polymorphic serialization:
* interfaces, sealed classes, abstract classes, classes marked by [Polymorphic].
*
* A compiler version `2.0.20` and higher is required.
* A compiler version `2.0.20` or higher is required.
*/
@ExperimentalSerializationApi
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
public annotation class KeepGeneratedSerializer
Expand Down
2 changes: 2 additions & 0 deletions docs/basic-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ For that purposes, [EncodeDefault] annotation can be used:

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

@Serializable
@OptIn(ExperimentalSerializationApi::class) // EncodeDefault is an experimental annotation for now
data class User(
val name: String,
@EncodeDefault(EncodeDefault.Mode.NEVER) val projects: List<Project> = emptyList()
Expand Down
Loading