Skip to content

Commit 26b4c94

Browse files
antohabySpace
authored andcommitted
[Test] Update warning message for tasks that disables GCC
^KT-51947
1 parent 538cb41 commit 26b4c94

File tree

2 files changed

+39
-2
lines changed
  • libraries/tools

2 files changed

+39
-2
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,27 @@ class HierarchicalMppIT : BaseGradleIT() {
679679
}
680680
}
681681
}
682+
@Test
683+
fun testHmppTasksReportConfigurationCacheWarningForGradleLessThan74() {
684+
val versionRequirement = GradleVersionRequired.InRange("6.8", "7.3")
685+
transformProjectWithPluginsDsl("hmppGradleConfigurationCache", versionRequirement).apply {
686+
build(":lib:publish") {
687+
assertSuccessful()
688+
}
689+
690+
// Assert that no warnings are shown when configuration-cache is not enabled
691+
build("clean", "assemble") {
692+
assertSuccessful()
693+
assertNotContains("""Task \S+ is not compatible with configuration cache""".toRegex())
694+
}
695+
696+
val options = defaultBuildOptions().copy(configurationCache = true, configurationCacheProblems = ConfigurationCacheProblems.FAIL)
697+
build("clean", "assemble", options = options) {
698+
assertFailed()
699+
assertContainsRegex("""Task \S+ is not compatible with configuration cache""".toRegex())
700+
}
701+
}
702+
}
682703

683704
private fun Project.testDependencyTransformations(
684705
subproject: String? = null,

libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/utils/configurationCache.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.utils
77

88
import org.gradle.api.Project
99
import org.gradle.api.Task
10+
import org.gradle.api.internal.StartParameterInternal
1011
import org.gradle.api.invocation.Gradle
1112

1213
internal fun isConfigurationCacheAvailable(gradle: Gradle) =
@@ -29,13 +30,28 @@ internal fun unavailableValueError(propertyName: String): Nothing =
2930
error("'$propertyName' should be available at configuration time but unavailable on configuration cache reuse")
3031

3132
fun Task.notCompatibleWithConfigurationCache(reason: String) {
32-
if (!isGradleVersionAtLeast(7, 4)) return
33+
val reportConfigurationCacheWarnings = try {
34+
val startParameters = project.gradle.startParameter as? StartParameterInternal
35+
startParameters?.run { isConfigurationCache && !isConfigurationCacheQuiet } ?: false
36+
} catch (_: IncompatibleClassChangeError) { // for cases when gradle is way too old
37+
false
38+
}
39+
40+
if (!isGradleVersionAtLeast(7, 4)) {
41+
if (reportConfigurationCacheWarnings) {
42+
logger.warn("Task $name is not compatible with configuration cache: $reason")
43+
}
44+
return
45+
}
46+
3347
try {
3448
val taskClass = Task::class.java
3549
val method = taskClass.getMethod("notCompatibleWithConfigurationCache", String::class.java)
3650

3751
method.invoke(this, reason)
3852
} catch (e: ReflectiveOperationException) {
39-
logger.warn("Can't mark task $this as notCompatibleWithConfigurationCache due to reflection issue", e)
53+
if (reportConfigurationCacheWarnings) {
54+
logger.warn("Reflection issue - task $name is not compatible with configuration cache: $reason", e)
55+
}
4056
}
4157
}

0 commit comments

Comments
 (0)