Migrate ConfigurationAvoidanceIT tests into new DSL.

^KT-45745 In Progress
This commit is contained in:
Yahor Berdnikau
2021-10-06 16:57:33 +02:00
parent 2f87c28634
commit 82d947d3a4
7 changed files with 114 additions and 76 deletions
@@ -5,70 +5,90 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.junit.Test
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.DisplayName
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.appendText
class ConfigurationAvoidanceIT : BaseGradleIT() {
@DisplayName("Tasks configuration avoidance")
@SimpleGradlePluginTests
@OptIn(ExperimentalPathApi::class)
class ConfigurationAvoidanceIT : KGPBaseTest() {
@Test
fun testUnrelatedTaskNotConfigured() = with(Project("simpleProject")) {
setupWorkingDir()
@DisplayName("Unrelated tasks are not configured")
@GradleTest
fun testUnrelatedTaskNotConfigured(gradleVersion: GradleVersion) {
project("simpleProject", gradleVersion) {
val expensivelyConfiguredTaskName = "expensivelyConfiguredTask"
val triggeredExpensiveConfigurationText = "Triggered expensive configuration!"
val expensivelyConfiguredTaskName = "expensivelyConfiguredTask"
gradleBuildScript().appendText("\n" + """
tasks.register("$expensivelyConfiguredTaskName") {
println("$triggeredExpensiveConfigurationText")
}
""".trimIndent())
build("compileKotlin") {
assertSuccessful()
assertNotContains(triggeredExpensiveConfigurationText)
}
}
@Test
fun testAndroidUnrelatedTaskNotConfigured() = with(
Project(
"AndroidProject",
gradleVersionRequirement = GradleVersionRequired.AtLeast("6.7.1")
)
) {
setupWorkingDir()
listOf("Android", "Test").forEach { subproject ->
gradleBuildScript(subproject).appendText("\n" + """
android {
applicationVariants.all {
it.getAidlCompileProvider().configure {
throw new RuntimeException("Task should not be configured.")
}
}
@Suppress("GroovyAssignabilityCheck")
rootBuildGradle.appendText(
//language=Groovy
"""
tasks.register("$expensivelyConfiguredTaskName") {
throw new GradleException("Should not configure expensive task!")
}
""".trimIndent()
)
build("compileKotlin")
}
}
gradleBuildScript("Lib").appendText(
"\n" + """
android {
libraryVariants.all {
it.getAidlCompileProvider().configure {
throw new RuntimeException("Task should not be configured.")
}
}
}
""".trimIndent()
)
build(
"help", options = defaultBuildOptions().copy(
androidGradlePluginVersion = AGPVersion.v4_2_0
)
@DisplayName("Android tasks are not configured")
@GradleTestVersions(minVersion = "6.7.1")
@GradleTest
fun testAndroidUnrelatedTaskNotConfigured(gradleVersion: GradleVersion) {
project(
"AndroidProject",
gradleVersion
) {
assertSuccessful()
listOf("Android", "Test").forEach { subproject ->
projectPath
.resolve(subproject)
.resolve("build.gradle")
.appendText(
//language=Groovy
"""
android {
applicationVariants.all {
it.getAidlCompileProvider().configure {
throw new RuntimeException("Task should not be configured.")
}
}
}
""".trimIndent()
)
}
projectPath
.resolve("Lib")
.resolve("build.gradle")
.appendText(
//language=Groovy
"""
android {
libraryVariants.all {
it.getAidlCompileProvider().configure {
throw new RuntimeException("Task should not be configured.")
}
}
}
""".trimIndent()
)
build(
"help",
buildOptions = defaultBuildOptions.copy(
androidVersion = TestVersions.AGP.AGP_42
)
)
}
}
}
@@ -102,7 +102,7 @@ class PureAndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
gradleBuildScript("Lib").apply {
writeText(
// Remove the Kotlin plugin from the consumer project to check how pure-AGP Kotlin-less consumers resolve the dependency
readText().checkedReplace("apply plugin: 'kotlin-android'", "//").let { text ->
readText().checkedReplace("id 'org.jetbrains.kotlin.android'", "//").let { text ->
// If the test case doesn't assume flavors, remove the flavor setup lines:
if (useFlavors) text else text.lines().filter { !it.trim().startsWith("flavor") }.joinToString("\n")
} + "\n" + """
@@ -1,7 +1,9 @@
import org.gradle.util.VersionNumber
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdkVersion 22
@@ -1,5 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -1,7 +1,9 @@
import org.gradle.util.VersionNumber
apply plugin: 'com.android.test'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.test'
id 'org.jetbrains.kotlin.android'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -1,21 +1,7 @@
buildscript {
repositories {
mavenLocal()
google()
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath('com.android.tools.build:gradle:' + android_tools_version)
}
}
allprojects {
repositories {
mavenLocal()
google()
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
}
}
@@ -1 +1,27 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
}
plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
id "org.jetbrains.kotlin.kapt" version "$kotlin_version"
id "org.jetbrains.kotlin.android" version "$kotlin_version"
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.android.application" ||
requested.id.id == "com.android.library" ||
requested.id.id == "com.android.feature" ||
requested.id.id == "com.android.test") {
useModule("com.android.tools.build:gradle:$android_tools_version")
}
}
}
}
include ':Android', ':Lib', ':Test'