Allow to suppress kotlinOptions.freeCompiler args modification warning

It could be done via 'gradle.properties':
'kotlin.options.suppressFreeCompilerArgsModificationWarning=true'

^KT-54888 Fixed
This commit is contained in:
Yahor Berdnikau
2022-11-14 11:32:39 +01:00
committed by Space Team
parent 2d6fb8a99a
commit 49a5e9b91d
10 changed files with 65 additions and 13 deletions
+1
View File
@@ -11,6 +11,7 @@ cacheRedirectorEnabled=true
#buildSrc.kotlin.version=1.1.50
kotlin.build.gradlePlugin.version=0.0.38
kotlin.options.suppressFreeCompilerArgsModificationWarning=true
# Please keep it in sync with root gradle.properties.
# It's currently needed for proper configuration cache work, the reason will be investigated later
+1
View File
@@ -42,6 +42,7 @@ kotlin.build.publishing.attempts=20
## The following properties can be added to your local.properties file to customize the build:
kotlin.jvm.target.validation.mode=error
kotlin.options.suppressFreeCompilerArgsModificationWarning=true
#attachedIntellijVersion=203 (or any other platform version)
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.DisplayName
import kotlin.io.path.appendText
internal class CompilerOptionsIT : KGPBaseTest() {
@@ -22,7 +23,36 @@ internal class CompilerOptionsIT : KGPBaseTest() {
internal fun compatibleWithKotlinDsl(gradleVersion: GradleVersion) {
project("buildSrcWithKotlinDslAndKgp", gradleVersion) {
build("tasks") {
assertOutputContains("kotlinOptions.freeCompilerArgs were changed on task execution phase:")
assertOutputContains("kotlinOptions.freeCompilerArgs were changed on task :compileKotlin execution phase:")
}
}
}
@DisplayName("Allow to suppress kotlinOptions.freeCompilerArgs on task execution modification warning")
@JvmGradlePluginTests
@GradleTest
internal fun suppressFreeArgsModification(gradleVersion: GradleVersion) {
project("simpleProject", gradleVersion) {
buildGradle.appendText(
"""
|
|tasks.named("compileKotlin") {
| doFirst {
| kotlinOptions.freeCompilerArgs += ["-module-name=java"]
| }
|}
""".trimMargin()
)
gradleProperties.appendText(
"""
|
|kotlin.options.suppressFreeCompilerArgsModificationWarning=true
""".trimMargin()
)
build("assemble") {
assertOutputDoesNotContain("kotlinOptions.freeCompilerArgs were changed on task")
}
}
}
@@ -409,6 +409,9 @@ internal class PropertiesProvider private constructor(private val project: Proje
val kotlinTestInferJvmVariant: Boolean
get() = booleanProperty("kotlin.test.infer.jvm.variant") ?: true
val kotlinOptionsSuppressFreeArgsModificationWarning: Boolean
get() = booleanProperty(PropertyNames.KOTLIN_OPTIONS_SUPPRESS_FREEARGS_MODIFICATION_WARNING) ?: false
enum class JvmTargetValidationMode {
IGNORE, WARNING, ERROR
}
@@ -493,6 +496,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
const val KOTLIN_JS_KARMA_BROWSERS = "kotlin.js.browser.karma.browsers"
const val KOTLIN_BUILD_REPORT_SINGLE_FILE = "kotlin.build.report.single_file"
const val KOTLIN_BUILD_REPORT_HTTP_URL = "kotlin.build.report.http.url"
const val KOTLIN_OPTIONS_SUPPRESS_FREEARGS_MODIFICATION_WARNING = "kotlin.options.suppressFreeCompilerArgsModificationWarning"
}
companion object {
@@ -298,6 +298,9 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
@get:Internal
val startParameters = BuildReportsService.getStartParameters(project)
@get:Internal
internal abstract val suppressKotlinOptionsFreeArgsModificationWarning: Property<Boolean>
internal fun reportingSettings() = buildReportsService.orNull?.parameters?.reportingSettings?.orNull ?: ReportingSettings()
@get:Internal
@@ -73,6 +73,9 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
}
task.compilerExecutionStrategy.convention(propertiesProvider.kotlinCompilerExecutionStrategy).finalizeValueOnRead()
task.useDaemonFallbackStrategy.convention(propertiesProvider.kotlinDaemonUseFallbackStrategy).finalizeValueOnRead()
task.suppressKotlinOptionsFreeArgsModificationWarning
.convention(propertiesProvider.kotlinOptionsSuppressFreeArgsModificationWarning)
.finalizeValueOnRead()
task.incremental = false
task.useModuleDetection.convention(false)
@@ -27,10 +27,7 @@ class KotlinJsOptionsCompat(
}
set(value) = if (isTaskExecuting) {
task().logger.warn(
"kotlinOptions.freeCompilerArgs were changed on task execution phase: ${value.joinToString()}\n" +
"This behaviour will be deprecated and become an error in future releases!"
)
task().nagUserFreeArgsModifiedOnExecution(value)
task().additionalFreeCompilerArgs = value
} else {
options.freeCompilerArgs.set(value)
@@ -25,10 +25,7 @@ class KotlinJvmOptionsCompat(
}
set(value) = if (isTaskExecuting) {
task().logger.warn(
"kotlinOptions.freeCompilerArgs were changed on task execution phase: ${value.joinToString()}\n" +
"This behaviour is deprecated and become an error in future releases!"
)
task().nagUserFreeArgsModifiedOnExecution(value)
task().additionalFreeCompilerArgs = value
} else {
options.freeCompilerArgs.set(value)
@@ -24,10 +24,7 @@ class KotlinMultiplatformCommonOptionsCompat(
}
set(value) = if (isTaskExecuting) {
task().logger.warn(
"kotlinOptions.freeCompilerArgs were changed on task execution phase: ${value.joinToString()}\n" +
"This behaviour will be deprecated and become an error in future releases!"
)
task().nagUserFreeArgsModifiedOnExecution(value)
task().additionalFreeCompilerArgs = value
} else {
options.freeCompilerArgs.set(value)
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.tasks.internal
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
internal fun AbstractKotlinCompile<*>.nagUserFreeArgsModifiedOnExecution(
freeArgsValue: List<String>
) {
if (!suppressKotlinOptionsFreeArgsModificationWarning.get()) {
logger.warn(
"kotlinOptions.freeCompilerArgs were changed on task $path execution phase: ${freeArgsValue.joinToString()}\n" +
"This behaviour is deprecated and become an error in future releases!"
)
}
}