Skip to content

Commit d8d1b62

Browse files
committed
Kotlin UP: Fulfill the new requirements for Kotlin User Projects (#4392)
1 parent e5bb191 commit d8d1b62

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
22
import org.jetbrains.kotlin.gradle.dsl.*
33
import org.gradle.kotlin.dsl.*
4+
import org.gradle.kotlin.dsl.withType
5+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
6+
import kotlin.collections.joinToString
47

58
buildscript {
69
if (shouldUseLocalMaven(rootProject)) {
@@ -171,3 +174,10 @@ if (isSnapshotTrainEnabled(rootProject)) {
171174
// Report Kotlin compiler version when building project
172175
println("Using Kotlin compiler version: ${KotlinCompilerVersion.VERSION}")
173176
}
177+
178+
tasks.withType<KotlinCompilationTask<*>>().configureEach {
179+
doFirst {
180+
logger.info("Added Kotlin compiler flags: ${compilerOptions.freeCompilerArgs.get().joinToString(", ")}")
181+
logger.info("allWarningsAsErrors=${compilerOptions.allWarningsAsErrors.get()}")
182+
}
183+
}

buildSrc/src/main/kotlin/CommunityProjectsBuild.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ fun KotlinCommonCompilerOptions.configureKotlinUserProject() {
201201
* See <https://github.com/Kotlin/kotlinx.coroutines/pull/4392#issuecomment-2775630200>
202202
*/
203203
fun KotlinCommonCompilerOptions.addExtraCompilerFlags(project: Project) {
204-
val extraOptions = project.providers.gradleProperty("kotlin_additional_cli_options").orNull
205-
if (extraOptions != null) {
206-
LOGGER.info("""Adding extra compiler flags '$extraOptions' for a compilation in the project $${project.name}""")
207-
extraOptions.split(" ").forEach {
208-
if (it.isNotEmpty()) freeCompilerArgs.add(it)
204+
val extraOptions = project.providers.gradleProperty("kotlin_additional_cli_options")
205+
.orNull?.let { options ->
206+
options.removeSurrounding("\"").split(" ").filter { it.isNotBlank() }
209207
}
208+
extraOptions?.forEach { option ->
209+
freeCompilerArgs.add(option)
210+
LOGGER.info("""Adding extra compiler flag '$option' for a compilation in the project $${project.name}""")
210211
}
211212
}

0 commit comments

Comments
 (0)