Skip to content

Commit fe98400

Browse files
author
Marcel Schnelle
authored
Migration to Gradle Kotlin DSL (#124)
1 parent 2f58b5e commit fe98400

File tree

23 files changed

+918
-873
lines changed

23 files changed

+918
-873
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defaults: &defaults
77
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError"'
88

99
cache_key: &cache_key
10-
key: jars-{{ checksum "build.gradle" }}-{{ checksum "android-junit5/build.gradle" }}-{{ checksum "android-junit5-tests/build.gradle" }}-{{ checksum "instrumentation/build.gradle" }}-{{ checksum "instrumentation-runner/build.gradle" }}-{{ checksum "sample/build.gradle" }}-{{ checksum "gradle.properties" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
10+
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "android-junit5/build.gradle.kts" }}-{{ checksum "android-junit5-tests/build.gradle.kts" }}-{{ checksum "instrumentation/build.gradle.kts" }}-{{ checksum "instrumentation-runner/build.gradle.kts" }}-{{ checksum "sample/build.gradle.kts" }}-{{ checksum "gradle/dependencies.gradle.kts" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
1111

1212
version: 2
1313
jobs:

android-junit5-tests/build.gradle

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
}

android-junit5/build.gradle

Lines changed: 0 additions & 82 deletions
This file was deleted.

android-junit5/build.gradle.kts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import de.mannodermaus.gradle.plugins.junit5.Artifact
2+
import de.mannodermaus.gradle.plugins.junit5.Artifacts
3+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
4+
5+
plugins {
6+
id("groovy")
7+
id("kotlin")
8+
id("java-gradle-plugin")
9+
id("jacoco")
10+
}
11+
12+
// ------------------------------------------------------------------------------------------------
13+
// Compilation Tweaks
14+
//
15+
// The plugin currently consists of a codebase wherein Groovy & Kotlin coexist.
16+
// Therefore, the compilation chain has to be well-defined to allow Kotlin
17+
// to call into Groovy code.
18+
//
19+
// The other way around ("call Kotlin from Groovy") is prohibited explicitly.
20+
// ------------------------------------------------------------------------------------------------
21+
val compileGroovy = tasks.getByName("compileGroovy") as AbstractCompile
22+
val compileKotlin = tasks.getByName("compileKotlin") as AbstractCompile
23+
val classesTask = tasks.getByName("classes")
24+
25+
compileGroovy.dependsOn.remove("compileJava")
26+
compileKotlin.dependsOn.add(compileGroovy)
27+
compileKotlin.classpath += project.files(compileGroovy.destinationDir)
28+
classesTask.dependsOn.add(compileKotlin)
29+
30+
// ------------------------------------------------------------------------------------------------
31+
// Plugin Resource Setup
32+
//
33+
// This block generates the required resource files
34+
// containing the identifiers with which the plugin can be applied to consumer projects.
35+
// ------------------------------------------------------------------------------------------------
36+
37+
val pluginClassName = "de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin"
38+
39+
gradlePlugin {
40+
isAutomatedPublishing = false
41+
plugins {
42+
register("shortIdentifier") {
43+
id = "android-junit5"
44+
implementationClass = pluginClassName
45+
}
46+
register("longIdentifier") {
47+
id = "de.mannodermaus.android-junit5"
48+
implementationClass = pluginClassName
49+
}
50+
}
51+
}
52+
53+
// ------------------------------------------------------------------------------------------------
54+
// Dependency Definitions
55+
// ------------------------------------------------------------------------------------------------
56+
57+
dependencies {
58+
compileOnly(kotlin("gradle-plugin", extra["versions.kotlin"] as String))
59+
implementation(kotlin("stdlib-jdk8", extra["versions.kotlin"] as String))
60+
implementation(gradleApi())
61+
implementation(extra["libs.javaSemver"] as String)
62+
implementation(extra["libs.annimonStream"] as String)
63+
implementation(extra["libs.junitPlatformCommons"] as String)
64+
implementation(extra["plugins.android"] as String)
65+
}
66+
67+
// ------------------------------------------------------------------------------------------------
68+
// Deployment Setup
69+
// ------------------------------------------------------------------------------------------------
70+
71+
val deployConfig by extra<Artifact> { Artifacts.Plugin }
72+
apply(from = "$rootDir/gradle/deployment.gradle.kts")

0 commit comments

Comments
 (0)