|
| 1 | +import de.mannodermaus.gradle.plugins.junit5.WriteClasspathResource |
| 2 | +import org.apache.tools.ant.filters.ReplaceTokens |
| 3 | +import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
| 4 | +import org.gradle.api.tasks.testing.logging.TestLogEvent |
| 5 | + |
| 6 | +plugins { |
| 7 | + id("groovy") |
| 8 | + id("java-gradle-plugin") |
| 9 | + id("java-library") |
| 10 | + id("idea") |
| 11 | + id("jacoco") |
| 12 | + id("kotlin") |
| 13 | +} |
| 14 | + |
| 15 | +// ------------------------------------------------------------------------------------------------ |
| 16 | +// Compilation Tweaks |
| 17 | +// |
| 18 | +// The plugin currently consists of a codebase wherein Groovy & Kotlin coexist. |
| 19 | +// Therefore, the compilation chain has to be well-defined to allow Kotlin |
| 20 | +// to call into Groovy code. |
| 21 | +// |
| 22 | +// The other way around ("call Kotlin from Groovy") is prohibited explicitly. |
| 23 | +// ------------------------------------------------------------------------------------------------ |
| 24 | +val compileTestGroovy = tasks.getByName("compileTestGroovy") as AbstractCompile |
| 25 | +val compileTestKotlin = tasks.getByName("compileTestKotlin") as AbstractCompile |
| 26 | +val testClassesTask = tasks.getByName("testClasses") |
| 27 | + |
| 28 | +compileTestGroovy.dependsOn.remove("compileTestJava") |
| 29 | +compileTestKotlin.dependsOn.add(compileTestGroovy) |
| 30 | +compileTestKotlin.classpath += project.files(compileTestGroovy.destinationDir) |
| 31 | +testClassesTask.dependsOn.add(compileTestKotlin) |
| 32 | + |
| 33 | +// Add custom dependency configurations |
| 34 | +configurations { |
| 35 | + create("functionalTest") { |
| 36 | + description = "Local dependencies used for compiling & running " + |
| 37 | + "tests source code in Gradle functional tests" |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +val processTestResources = tasks.getByName("processTestResources") as Copy |
| 42 | +processTestResources.apply { |
| 43 | + val tokens = mapOf( |
| 44 | + "COMPILE_SDK_VERSION" to project.extra["android.compileSdkVersion"] as String, |
| 45 | + "BUILD_TOOLS_VERSION" to project.extra["android.buildToolsVersion"] as String, |
| 46 | + "MIN_SDK_VERSION" to (project.extra["android.sampleMinSdkVersion"] as Int).toString(), |
| 47 | + "TARGET_SDK_VERSION" to (project.extra["android.targetSdkVersion"] as Int).toString() |
| 48 | + ) |
| 49 | + |
| 50 | + inputs.properties(tokens) |
| 51 | + |
| 52 | + from(sourceSets["test"].resources.srcDirs) { |
| 53 | + include("**/testenv.properties") |
| 54 | + filter(ReplaceTokens::class, mapOf("tokens" to tokens)) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +tasks.withType<Test> { |
| 59 | + failFast = true |
| 60 | + useJUnitPlatform() |
| 61 | + testLogging { |
| 62 | + events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) |
| 63 | + exceptionFormat = TestExceptionFormat.FULL |
| 64 | + } |
| 65 | + |
| 66 | + // Enable this line to run disable running Functional Tests on the local device |
| 67 | +// environment("CI", "true") |
| 68 | +} |
| 69 | + |
| 70 | +dependencies { |
| 71 | + testImplementation(project(":android-junit5")) |
| 72 | + testImplementation(kotlin("gradle-plugin", extra["versions.kotlin"] as String)) |
| 73 | + testImplementation(extra["plugins.android"] as String) |
| 74 | + testImplementation(extra["libs.commonsIO"] as String) |
| 75 | + testImplementation(extra["libs.commonsLang"] as String) |
| 76 | + testImplementation(extra["libs.junit4"] as String) |
| 77 | + testImplementation(extra["libs.junitJupiterApi"] as String) |
| 78 | + testImplementation(extra["libs.junitJupiterParams"] as String) |
| 79 | + testImplementation(extra["libs.spekApi"] as String) |
| 80 | + testImplementation(extra["libs.junitPioneer"] as String) |
| 81 | + testImplementation(extra["libs.assertjCore"] as String) |
| 82 | + testImplementation(extra["libs.mockito"] as String) |
| 83 | + |
| 84 | + testRuntimeOnly(extra["libs.junitJupiterEngine"] as String) |
| 85 | + testRuntimeOnly(extra["libs.spekEngine"] as String) |
| 86 | + |
| 87 | + // Compilation of local classpath for functional tests |
| 88 | + val functionalTest by configurations |
| 89 | + functionalTest(kotlin("compiler-embeddable", extra["versions.kotlin"] as String)) |
| 90 | + functionalTest(extra["libs.junit4"] as String) |
| 91 | + functionalTest(extra["plugins.android"] as String) |
| 92 | + functionalTest(extra["libs.junitJupiterApi"] as String) |
| 93 | + functionalTest(extra["libs.junitJupiterEngine"] as String) |
| 94 | +} |
| 95 | + |
| 96 | +// Resource Writers |
| 97 | +tasks.create("writePluginClasspath", WriteClasspathResource::class) { |
| 98 | + inputFiles = sourceSets["test"].runtimeClasspath |
| 99 | + outputDir = File("$buildDir/resources/test") |
| 100 | + resourceFileName = "plugin-classpath.txt" |
| 101 | +} |
| 102 | + |
| 103 | +tasks.create("writeFunctionalTestCompileClasspath", WriteClasspathResource::class) { |
| 104 | + inputFiles = configurations["functionalTest"] |
| 105 | + outputDir = File("$buildDir/resources/test") |
| 106 | + resourceFileName = "functional-test-compile-classpath.txt" |
| 107 | +} |
| 108 | + |
| 109 | +val testTask = tasks.getByName("test") |
| 110 | +tasks.withType<WriteClasspathResource> { |
| 111 | + processTestResources.finalizedBy(this) |
| 112 | + testTask.mustRunAfter(this) |
| 113 | +} |
0 commit comments