[Gradle] Fix eager task realization due to attributes querying

Gradle 8.3+ starts triggering JVM eager tasks creating via eagerly
configured attributes that we copy over from the Gradle JVM plugin for
Kotlin compilation. The fix is to migrate to '.attributeProvider()' API
to configure the attribute.

^KT-60664 In Progress
This commit is contained in:
Yahor Berdnikau
2023-12-21 22:18:33 +01:00
committed by Space Team
parent 2da6946ac2
commit dbd77fc785
58 changed files with 563 additions and 222 deletions
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.configuration.WarningMode
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.DisplayName
@@ -27,7 +26,8 @@ class ConfigurationAvoidanceIT : KGPBaseTest() {
@JvmGradlePluginTests
@GradleTestVersions(
additionalVersions = [TestVersions.Gradle.G_7_3]
additionalVersions = [TestVersions.Gradle.G_7_3],
maxVersion = TestVersions.Gradle.G_8_3
)
@DisplayName("KGP/Jvm does not eagerly configure any tasks")
@GradleTest
@@ -648,7 +648,7 @@ class KotlinGradleIT : KGPBaseTest() {
subProject("projB").buildGradle.appendText("\nkotlin.target.attributes.attribute(targetAttribute, \"bar\")")
buildAndFail(":projB:compileKotlin") {
when {
gradleVersion < GradleVersion.version("6.8.4") -> {
gradleVersion <= GradleVersion.version(TestVersions.Gradle.G_6_8) -> {
assertOutputContains(
"No matching variant of project :projA was found. The consumer was configured to find an API of a library " +
"compatible with Java 8, preferably in the form of class files, " +
@@ -659,14 +659,19 @@ class KotlinGradleIT : KGPBaseTest() {
)
}
else -> {
assertOutputContains(
"No matching variant of project :projA was found. The consumer was configured to find a library for use during compile-time, " +
"compatible with Java 8, preferably in the form of class files, " +
"preferably optimized for standard JVMs, and its dependencies declared externally, " +
"as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm', " +
"attribute 'com.example.compilation' with value 'foo', " +
"attribute 'com.example.target' with value 'bar' but:"
)
// Attributes may come in random order
val attributeMatchingString = output.lineSequence().find {
it.trimStart().startsWith(
"> No matching variant of project :projA was found. " +
"The consumer was configured to find a library for use during compile-time, " +
"compatible with Java 8, preferably in the form of class files, " +
"preferably optimized for standard JVMs, and its dependencies declared externally, "
)
}
assertNotNull(attributeMatchingString, "Expected variant mismatch string is not found")
assertTrue(attributeMatchingString.contains("attribute 'com.example.compilation' with value 'foo'"))
assertTrue(attributeMatchingString.contains("attribute 'com.example.target' with value 'bar'"))
assertTrue(attributeMatchingString.contains("attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'"))
}
}
}
@@ -681,7 +686,7 @@ class KotlinGradleIT : KGPBaseTest() {
)
buildAndFail(":projB:compileKotlin") {
when {
gradleVersion < GradleVersion.version("6.8.4") -> {
gradleVersion <= GradleVersion.version(TestVersions.Gradle.G_6_8) -> {
assertOutputContains(
"No matching variant of project :projA was found. The consumer was configured to find an API of a library " +
"compatible with Java 8, preferably in the form of class files, and its dependencies declared externally, " +
@@ -691,14 +696,19 @@ class KotlinGradleIT : KGPBaseTest() {
)
}
else -> {
assertOutputContains(
"No matching variant of project :projA was found. The consumer was configured to find a library for use during compile-time, " +
"compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, " +
"and its dependencies declared externally, " +
"as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm', " +
"attribute 'com.example.compilation' with value 'bar', " +
"attribute 'com.example.target' with value 'foo' but:"
)
// Attributes may come in random order
val attributeMatchingString = output.lineSequence().find {
it.contains(
"No matching variant of project :projA was found. " +
"The consumer was configured to find a library for use during compile-time, " +
"compatible with Java 8, preferably in the form of class files, " +
"preferably optimized for standard JVMs, and its dependencies declared externally, "
)
}
assertNotNull(attributeMatchingString, "Expected variant mismatch string is not found")
assertTrue(attributeMatchingString.contains("attribute 'com.example.compilation' with value 'bar'"))
assertTrue(attributeMatchingString.contains("attribute 'com.example.target' with value 'foo'"))
assertTrue(attributeMatchingString.contains("attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'"))
}
}
}