diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts index e435921ee12..1b10c8e8740 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts @@ -1,154 +1,162 @@ -apply plugin: 'kotlin' -apply plugin: 'jps-compatible' +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.pill.PillExtension + +plugins { + kotlin("jvm") + id("jps-compatible") +} pill { - variant = "FULL" + variant = PillExtension.Variant.FULL } -configureJvmProject(project) - -repositories { - mavenLocal() - jcenter() -} +val kotlinGradlePluginTest = project(":kotlin-gradle-plugin").sourceSets.getByName("test") dependencies { - testCompile project(':kotlin-gradle-plugin') - testCompile project(':kotlin-gradle-plugin').sourceSets.test.output - testCompile project(':kotlin-gradle-subplugin-example') - testCompile project(':kotlin-allopen') - testCompile project(':kotlin-noarg') - testCompile project(':kotlin-sam-with-receiver') - testCompile project(':kotlin-test:kotlin-test-jvm') + testCompile(project(":kotlin-gradle-plugin")) + testCompile(kotlinGradlePluginTest.output) + testCompile(project(":kotlin-gradle-subplugin-example")) + testCompile(project(":kotlin-allopen")) + testCompile(project(":kotlin-noarg")) + testCompile(project(":kotlin-sam-with-receiver")) + testCompile(project(":kotlin-test:kotlin-test-jvm")) - testCompile project(path: ':kotlin-compiler-embeddable', configuration: 'runtimeJar') + testCompile(projectRuntimeJar(":kotlin-compiler-embeddable")) // testCompileOnly dependency on non-shaded artifacts is needed for IDE support // testRuntime on shaded artifact is needed for running tests with shaded compiler - testCompileOnly (project(path: ':kotlin-gradle-plugin-test-utils-embeddable', configuration: 'compile')) - testRuntime (project(path: ':kotlin-gradle-plugin-test-utils-embeddable', configuration: 'runtimeJar')) + testCompileOnly(project(path = ":kotlin-gradle-plugin-test-utils-embeddable", configuration = "compile")) + testRuntime(projectRuntimeJar(":kotlin-gradle-plugin-test-utils-embeddable")) - testCompile project(path: ':examples:annotation-processor-example') - testCompile project(':kotlin-stdlib-jdk8') - testCompile project(':kotlin-reflect') - testCompile project(':kotlin-android-extensions') + testCompile(project(path = ":examples:annotation-processor-example")) + testCompile(project(":kotlin-stdlib-jdk8")) + testCompile(project(":kotlin-reflect")) + testCompile(project(":kotlin-android-extensions")) - testCompile gradleApi() + testCompile(gradleApi()) - testRuntime project(path: ':kotlin-android-extensions', configuration: 'runtimeJar') + testRuntime(projectRuntimeJar(":kotlin-android-extensions")) - // Workaround for missing transitive import of the common project `kotlin-test-common` + // Workaround for missing transitive import of the common(project `kotlin-test-common` // for `kotlin-test-jvm` into the IDE: - testCompileOnly(project(':kotlin-test:kotlin-test-common')) { transitive = false } + testCompileOnly(project(":kotlin-test:kotlin-test-common")) { isTransitive = false } } -// Include Gradle task properties validation into the testing procedure: -test.dependsOn(":kotlin-gradle-plugin:validateTaskProperties") +val jpsIncrementalTestsClass = "**/KotlinGradlePluginJpsParametrizedIT.class" -test.dependsOn(":kotlin-allopen:install", - ":kotlin-noarg:install", - ":kotlin-sam-with-receiver:install", - ":kotlin-android-extensions:install", - ":kotlin-build-common:install", - ":kotlin-compiler-embeddable:install", - ":kotlin-gradle-plugin:install", - ":kotlin-reflect:install", - ":kotlin-annotation-processing-gradle:install", - ":kotlin-test:kotlin-test-jvm:install", - ":kotlin-gradle-subplugin-example:install", - ":kotlin-stdlib-jdk8:install", - ":examples:annotation-processor-example:install", - ":kotlin-scripting-common:install", - ":kotlin-scripting-jvm:install", - ":kotlin-scripting-compiler-embeddable:install") +projectTest { + executable = "${rootProject.extra["JDK_18"]!!}/bin/java" + dependsOn(":kotlin-gradle-plugin:validateTaskProperties") + dependsOn( + ":kotlin-allopen:install", + ":kotlin-noarg:install", + ":kotlin-sam-with-receiver:install", + ":kotlin-android-extensions:install", + ":kotlin-build-common:install", + ":kotlin-compiler-embeddable:install", + ":kotlin-gradle-plugin:install", + ":kotlin-reflect:install", + ":kotlin-annotation-processing-gradle:install", + ":kotlin-test:kotlin-test-jvm:install", + ":kotlin-gradle-subplugin-example:install", + ":kotlin-stdlib-jdk8:install", + ":examples:annotation-processor-example:install", + ":kotlin-scripting-common:install", + ":kotlin-scripting-jvm:install", + ":kotlin-scripting-compiler-embeddable:install" + ) + exclude(jpsIncrementalTestsClass) +} +tasks.register("testsFromJps") { + include(jpsIncrementalTestsClass) + dependsOn(tasks.getByName("test").dependsOn) +} + +tasks.register("testAdvanceGradleVersion") { + val gradleVersionForTests = "4.5.1" + systemProperty("kotlin.gradle.version.for.tests", gradleVersionForTests) + dependsOn(tasks.getByName("test").dependsOn) + exclude(jpsIncrementalTestsClass) +} + +tasks.named("check") { + dependsOn("testAdvanceGradleVersion") +} -// Validate that all dependencies 'install' tasks are added to 'test' dependencies -// Test dependencies are specified as paths to avoid forcing dependency resolution -// and also to avoid specifying evaluationDependsOn for each testCompile dependency. gradle.taskGraph.whenReady { - def notAddedTestTasks = [] - def testDependencies = test.dependsOn + // Validate that all dependencies "install" tasks are added to "test" dependencies + // Test dependencies are specified as paths to avoid forcing dependency resolution + // and also to avoid specifying evaluationDependsOn for each testCompile dependency. + + val notAddedTestTasks = hashSetOf() + val test = tasks.getByName("test") + val testDependencies = test.dependsOn for (dependency in configurations.getByName("testCompile").allDependencies) { - if (!(dependency instanceof ProjectDependency)) continue + if (dependency !is ProjectDependency) continue - def task = dependency.dependencyProject.tasks.findByName("install") + val task = dependency.dependencyProject.tasks.findByName("install") if (task != null && !testDependencies.contains(task.path)) { notAddedTestTasks.add("\"${task.path}\"") } } if (!notAddedTestTasks.isEmpty()) { - throw new GradleException("Add the following tasks to ${test.path} dependencies:\n ${notAddedTestTasks.join(",\n ")}") + throw GradleException("Add the following tasks to ${test.path} dependencies:\n ${notAddedTestTasks.joinToString(",\n ")}") } } -processResources { - expand(project.properties) +tasks.withType { + kotlinOptions.jdkHome = rootProject.extra["JDK_18"] as String + kotlinOptions.jvmTarget = "1.8" } -compileTestKotlin.kotlinOptions.jdkHome = JDK_18 -compileTestKotlin.kotlinOptions.jvmTarget = "1.8" - -tasks.withType(Test) { +tasks.withType { onlyIf { !project.hasProperty("noTest") } - executable = "${JDK_18}/bin/java" + executable = "${rootProject.extra["JDK_18"]!!}/bin/java" - systemProperty("kotlinVersion", kotlinVersion) + systemProperty("kotlinVersion", rootProject.extra["kotlinVersion"] as String) systemProperty("runnerGradleVersion", gradle.gradleVersion) - def mavenLocalRepo = System.getProperty("maven.repo.local") + val mavenLocalRepo = System.getProperty("maven.repo.local") if (mavenLocalRepo != null) { systemProperty("maven.repo.local", mavenLocalRepo) } - TasksKt.useAndroidSdk(it) + useAndroidSdk() testLogging { // set options for log level LIFECYCLE - events "passed", "skipped", "failed", "standardOut" - showExceptions true - exceptionFormat "full" - showCauses true - showStackTraces true + events("passed", "skipped", "failed", "standardOut") + showExceptions = true + exceptionFormat = TestExceptionFormat.FULL + showCauses = true + showStackTraces = true // set options for log level DEBUG and INFO debug { - events "started", "passed", "skipped", "failed", "standardOut", "standardError" - exceptionFormat "full" + events("started", "passed", "skipped", "failed", "standardOut", "standardError") + exceptionFormat = TestExceptionFormat.FULL } info.events = debug.events info.exceptionFormat = debug.exceptionFormat - afterSuite { desc, result -> - if (!desc.parent) { // will match the outermost suite - def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" - def startItem = '| ', endItem = ' |' - def repeatLength = startItem.length() + output.length() + endItem.length() - println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength)) + addTestListener(object : TestListener { + override fun afterSuite(desc: TestDescriptor, result: TestResult) { + if (desc.parent == null) { // will match the outermost suite + val output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" + val startItem = "| " + val endItem = " |" + val repeatLength = startItem.length + output.length + endItem.length + println("\n" + ("-".repeat(repeatLength)) + "\n" + startItem + output + endItem + "\n" + ("-".repeat(repeatLength))) + } } - } + + override fun beforeSuite(suite: TestDescriptor) {} + override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {} + override fun beforeTest(testDescriptor: TestDescriptor) {} + }) } -} - -def jpsIncrementalTestsClass = '**/KotlinGradlePluginJpsParametrizedIT.class' - -test { - dependsOn(":kotlin-gradle-plugin:validateTaskProperties") - exclude jpsIncrementalTestsClass -} - -task testsFromJps(type: Test) { - include jpsIncrementalTestsClass - dependsOn = test.dependsOn -} - -task testAdvanceGradleVersion(type: Test) { - def gradleVersionForTests = "4.5.1" - systemProperty("kotlin.gradle.version.for.tests", gradleVersionForTests) - dependsOn = test.dependsOn - exclude jpsIncrementalTestsClass -} - -check.dependsOn(testAdvanceGradleVersion) \ No newline at end of file +} \ No newline at end of file