Skip to content

Enable allWarningsAsErrors compiler option for :runtime and :examples:kotlin-multiplatform projects #165

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

Merged
merged 5 commits into from
Dec 7, 2023

Conversation

qurbonzoda
Copy link
Contributor

@qurbonzoda qurbonzoda commented Nov 28, 2023

The main reason behind enabling allWarningsAsErrors is to make sure deprecations/warnings in Kotlin compiler and KGP are detected in the aggregate build. So that the person who makes those changes comes and fixes usages in this library.

Followup to #164

compilerOptions.freeCompilerArgs.addAll(
"-opt-in=kotlin.experimental.ExperimentalNativeApi",
"-opt-in=kotlin.native.runtime.NativeRuntimeApi",
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could continue using languageSettings.optIn DSL but move it to nativeMain source set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this approach doesn't work. The opt-ins are not passed to the dependent source sets automatically.
This causes:

Inconsistent settings for Kotlin source sets: 'androidNativeArm32Main' depends on 'nativeMain'
  'androidNativeArm32Main': set of opt-in annotations in use is []
  'nativeMain': set of opt-in annotations in use is [kotlin.experimental.ExperimentalNativeApi, kotlin.native.runtime.NativeRuntimeApi, kotlinx.cinterop.ExperimentalForeignApi]
  The dependent source set must use all opt-in annotations that its dependency uses.

@@ -30,6 +30,12 @@ kotlin {

applyDefaultHierarchyTemplate()

targets.configureEach {
compilations.configureEach {
kotlinOptions.allWarningsAsErrors = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compilerOptions can be used instead of kotlinOptions to avoid further changes when the latter is deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
But configuring compilerOptions in Groovy is not as handy as in Kotlin.
It is not possible to call compilerOptions.configure {} function because of resolution ambiguity between fun configure(configuration: T.() -> Unit) and fun configure(configuration: Action<T>).
So the compilerOptions.options needs to be configured directly.

@qurbonzoda qurbonzoda mentioned this pull request Nov 29, 2023
@qurbonzoda qurbonzoda force-pushed the qurbonzoda/enable-default-template-hierarchy branch from 0152cb5 to bf8df6c Compare December 7, 2023 18:24
@qurbonzoda qurbonzoda force-pushed the qurbonzoda/enable-allWarningsAsErrors branch from 06a0df6 to 70d5d37 Compare December 7, 2023 18:29
@qurbonzoda qurbonzoda changed the base branch from qurbonzoda/enable-default-template-hierarchy to master December 7, 2023 18:29
@qurbonzoda qurbonzoda merged commit 29b873e into master Dec 7, 2023
OndrejSliva pushed a commit to OndrejSliva/kotlinx-benchmark that referenced this pull request Jan 10, 2024
…e.googlejavaformat-google-java-format-1.19.1

build(deps): bump com.google.googlejavaformat:google-java-format from 1.19.0 to 1.19.1
@qurbonzoda qurbonzoda deleted the qurbonzoda/enable-allWarningsAsErrors branch February 11, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants