in buildSrc/src/main/kotlin/AgpFunctionalTestPlugin.kt [27:83]
override fun apply(project: Project) {
project.pluginManager.apply(VersionPlugin::class.java)
project.plugins.withType(JavaLibraryPlugin::class.java) {
val sourceSets = project.extensions.getByType(SourceSetContainer::class.java)
val functionalSourceSet = sourceSets.create("functionalTest")
val pluginExtension = project.extensions.getByType(GradlePluginDevelopmentExtension::class.java)
pluginExtension.testSourceSets(functionalSourceSet)
project.configurations.getByName("functionalTestImplementation").extendsFrom(project.configurations.getByName("testImplementation"))
val functionalTest = project.tasks.register("functionalTest", Test::class.java) {
it.testClassesDirs = functionalSourceSet.output.classesDirs
it.classpath = functionalSourceSet.runtimeClasspath
}
val agpClasspath = project.configurations.maybeCreate("agpClasspath")
val outputFileLocation = project.layout.buildDirectory.file("agpclasspath.txt")
val agpTask = project.tasks.register("agpTask", AgpClasspathTask::class.java) {
it.classpath.from(agpClasspath.incoming.artifacts.artifactFiles)
it.outputFile.set(outputFileLocation)
}
functionalTest.configure {
@Suppress("UnstableApiUsage")
it.systemProperty("agp.classpath", outputFileLocation.forUseAtConfigurationTime().get().asFile.absolutePath)
it.environment("ANDROID_SDK_ROOT", System.getenv("ANDROID_SDK_ROOT"))
it.environment("AGP_VERSION", Versions.agpVersion)
it.environment("KOTLIN_VERSION", Versions.kotlinVersion)
it.environment("GRADLE_VERSION", Versions.gradleVersion)
it.dependsOn(agpTask)
}
project.dependencies.apply {
add(agpClasspath.name, "com.android.tools.build:gradle:${Versions.agpVersion}")
add(agpClasspath.name, "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinVersion}")
}
val initScriptLinter = project.tasks.register("initScriptLinter", DefaultTask::class.java) {
it.doLast {
val pluginVersion = "${Versions.pluginArtifactId}:${Versions.pluginVersion}"
require(
project.rootProject.file("initscript/init.gradle").readText().contains(pluginVersion)
) {
throw AssertionError("init script does not reference $pluginVersion")
}
}
}
project.tasks.named("check") {
it.dependsOn(functionalTest)
it.dependsOn(initScriptLinter)
}
}
}