Provide approximate stacktrace to freeCompilerArgs modification
Will help users to understand where exactly 'kotlinOptions .freeCompilerArgs' were modified on execution phase. ^KT-55544 Fixed
This commit is contained in:
committed by
Space Team
parent
ff96033e95
commit
c65b689fa0
+11
-3
@@ -13,16 +13,24 @@ import kotlin.io.path.appendText
|
||||
|
||||
internal class CompilerOptionsIT : KGPBaseTest() {
|
||||
|
||||
// In Gradle 7.3-7.5 'kotlin-dsl' plugin tries to set up freeCompilerArgs in doFirst task action
|
||||
// In Gradle 7.3-8.0 'kotlin-dsl' plugin tries to set up freeCompilerArgs in doFirst task action
|
||||
// Related issue: https://github.com/gradle/gradle/issues/22091
|
||||
@DisplayName("Allows to set kotlinOptions.freeCompilerArgs on task execution with warning")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTestVersions(
|
||||
minVersion = TestVersions.Gradle.G_7_3,
|
||||
maxVersion = TestVersions.Gradle.G_7_5
|
||||
minVersion = TestVersions.Gradle.G_7_3
|
||||
)
|
||||
@GradleTest
|
||||
internal fun compatibleWithKotlinDsl(gradleVersion: GradleVersion) {
|
||||
project("buildSrcWithKotlinDslAndKgp", gradleVersion) {
|
||||
gradleProperties
|
||||
.appendText(
|
||||
"""
|
||||
|
|
||||
|systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true
|
||||
""".trimMargin()
|
||||
)
|
||||
|
||||
build("tasks") {
|
||||
assertOutputContains("kotlinOptions.freeCompilerArgs were changed on task :compileKotlin execution phase:")
|
||||
}
|
||||
|
||||
+25
-1
@@ -11,9 +11,33 @@ internal fun AbstractKotlinCompile<*>.nagUserFreeArgsModifiedOnExecution(
|
||||
freeArgsValue: List<String>
|
||||
) {
|
||||
if (!suppressKotlinOptionsFreeArgsModificationWarning.get()) {
|
||||
// Trying to approximately filter out KGP and non-related Gradle/Java/Groovy classes from stacktrace
|
||||
val modificationStacktrace = Thread.currentThread().stackTrace
|
||||
.asSequence()
|
||||
.filter {
|
||||
!it.className.startsWith("org.jetbrains.kotlin.gradle") &&
|
||||
!it.className.startsWith("org.gradle.api") &&
|
||||
!it.className.startsWith("org.gradle.internal") &&
|
||||
!it.className.startsWith("org.gradle.execution") &&
|
||||
!it.className.startsWith("java.") &&
|
||||
!it.className.startsWith("sun.") &&
|
||||
!it.className.startsWith("groovy.") &&
|
||||
!it.className.startsWith("kotlin.") &&
|
||||
!it.className.startsWith("org.codehaus.groovy.")
|
||||
}
|
||||
.takeWhile {
|
||||
!it.className.startsWith("org.gradle.composite") &&
|
||||
!it.className.startsWith("org.gradle.configuration.internal")
|
||||
}
|
||||
.joinToString(separator = "\n") {
|
||||
" $it"
|
||||
}
|
||||
|
||||
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!"
|
||||
"This behaviour is deprecated and become an error in future releases!\n" +
|
||||
"Approximate place of modification at execution phase:\n" +
|
||||
modificationStacktrace
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user