Skip to content

Commit 61a1166

Browse files
author
Marcel Schnelle
authored
Type-safe config access (#137)
* Remove extra-based properties & clean up build files through buildSrcVersions plugin * Force-use strings in ReplaceToken expressions * Explicitly depend on Gradle TestKit since that’s apparently vanished now
1 parent c9b5676 commit 61a1166

File tree

16 files changed

+414
-230
lines changed

16 files changed

+414
-230
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.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" }}
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/wrapper/gradle-wrapper.properties" }}
1111

1212
version: 2
1313
jobs:

android-junit5-tests/build.gradle.kts

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import de.mannodermaus.gradle.plugins.junit5.WriteClasspathResource
21
import org.apache.tools.ant.filters.ReplaceTokens
32
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
43
import org.gradle.api.tasks.testing.logging.TestLogEvent
54

65
plugins {
76
id("groovy")
8-
id("java-gradle-plugin")
97
id("java-library")
108
id("idea")
119
id("jacoco")
@@ -55,10 +53,10 @@ configurations {
5553
val processTestResources = tasks.getByName("processTestResources") as Copy
5654
processTestResources.apply {
5755
val tokens = mapOf(
58-
"COMPILE_SDK_VERSION" to project.extra["android.compileSdkVersion"] as String,
59-
"BUILD_TOOLS_VERSION" to project.extra["android.buildToolsVersion"] as String,
60-
"MIN_SDK_VERSION" to (project.extra["android.sampleMinSdkVersion"] as Int).toString(),
61-
"TARGET_SDK_VERSION" to (project.extra["android.targetSdkVersion"] as Int).toString()
56+
"COMPILE_SDK_VERSION" to Android.compileSdkVersion,
57+
"BUILD_TOOLS_VERSION" to Android.buildToolsVersion,
58+
"MIN_SDK_VERSION" to Android.sampleMinSdkVersion.toString(),
59+
"TARGET_SDK_VERSION" to Android.targetSdkVersion.toString()
6260
)
6361

6462
inputs.properties(tokens)
@@ -76,44 +74,42 @@ tasks.withType<Test> {
7674
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
7775
exceptionFormat = TestExceptionFormat.FULL
7876
}
79-
80-
// Uncomment this line to run disable running Functional Tests on the local device
81-
// environment("CI", "true")
8277
}
8378

8479
dependencies {
8580
testImplementation(project(":android-junit5"))
86-
testImplementation(kotlin("gradle-plugin", extra["versions.kotlin"] as String))
87-
testImplementation(extra["plugins.android"] as String)
88-
testImplementation(extra["libs.commonsIO"] as String)
89-
testImplementation(extra["libs.commonsLang"] as String)
90-
testImplementation(extra["libs.junit4"] as String)
91-
testImplementation(extra["libs.junitJupiterApi"] as String)
92-
testImplementation(extra["libs.junitJupiterParams"] as String)
93-
testImplementation(extra["libs.spekApi"] as String)
94-
testImplementation(extra["libs.junitPioneer"] as String)
95-
testImplementation(extra["libs.assertjCore"] as String)
96-
testImplementation(extra["libs.mockito"] as String)
97-
98-
testRuntimeOnly(extra["libs.junitJupiterEngine"] as String)
99-
testRuntimeOnly(extra["libs.junitVintageEngine"] as String)
100-
testRuntimeOnly(extra["libs.spekEngine"] as String)
81+
testImplementation(gradleTestKit())
82+
testImplementation(Libs.kotlin_gradle_plugin)
83+
testImplementation(Libs.com_android_tools_build_gradle)
84+
testImplementation(Libs.commons_io)
85+
testImplementation(Libs.commons_lang)
86+
testImplementation(Libs.junit)
87+
testImplementation(Libs.junit_jupiter_api)
88+
testImplementation(Libs.junit_jupiter_params)
89+
testImplementation(Libs.spek_api)
90+
testImplementation(Libs.junit_pioneer)
91+
testImplementation(Libs.assertj_core)
92+
testImplementation(Libs.mockito_core)
93+
94+
testRuntimeOnly(Libs.junit_jupiter_engine)
95+
testRuntimeOnly(Libs.junit_vintage_engine)
96+
testRuntimeOnly(Libs.spek_junit_platform_engine)
10197

10298
// Compilation of local classpath for functional tests
10399
val functionalTest by configurations
104-
functionalTest(kotlin("compiler-embeddable", extra["versions.kotlin"] as String))
105-
functionalTest(extra["libs.junit4"] as String)
106-
functionalTest(extra["libs.junitJupiterApi"] as String)
107-
functionalTest(extra["libs.junitJupiterEngine"] as String)
100+
functionalTest(Libs.kotlin_compiler_embeddable)
101+
functionalTest(Libs.junit)
102+
functionalTest(Libs.junit_jupiter_api)
103+
functionalTest(Libs.junit_jupiter_engine)
108104

109105
val functionalTestAgp32X by configurations
110-
functionalTestAgp32X(extra["plugins.android.32X"] as String)
106+
functionalTestAgp32X("com.android.tools.build:gradle:3.2.1")
111107

112108
val functionalTestAgp33X by configurations
113-
functionalTestAgp33X(extra["plugins.android.33X"] as String)
109+
functionalTestAgp33X("com.android.tools.build:gradle:3.3.0-rc03")
114110

115111
val functionalTestAgp34X by configurations
116-
functionalTestAgp34X(extra["plugins.android.34X"] as String)
112+
functionalTestAgp34X("com.android.tools.build:gradle:3.4.0-alpha09")
117113
}
118114

119115
// Resource Writers

android-junit5/build.gradle.kts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import de.mannodermaus.gradle.plugins.junit5.Artifact
2-
import de.mannodermaus.gradle.plugins.junit5.Artifacts
31
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
42

53
plugins {
@@ -55,18 +53,19 @@ gradlePlugin {
5553
// ------------------------------------------------------------------------------------------------
5654

5755
dependencies {
58-
compileOnly(kotlin("gradle-plugin", extra["versions.kotlin"] as String))
59-
implementation(kotlin("stdlib-jdk8", extra["versions.kotlin"] as String))
56+
compileOnly(Libs.kotlin_gradle_plugin)
57+
6058
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)
59+
implementation(Libs.kotlin_stdlib_jdk8)
60+
implementation(Libs.java_semver)
61+
implementation(Libs.stream)
62+
implementation(Libs.junit_platform_commons)
63+
implementation(Libs.com_android_tools_build_gradle)
6564
}
6665

6766
// ------------------------------------------------------------------------------------------------
6867
// Deployment Setup
6968
// ------------------------------------------------------------------------------------------------
7069

71-
val deployConfig by extra<Artifact> { Artifacts.Plugin }
70+
val deployConfig by extra<Deployed> { Artifacts.Plugin }
7271
apply(from = "$rootDir/gradle/deployment.gradle")

build.gradle.kts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,32 @@
11
import java.util.Properties
22

33
buildscript {
4-
rootProject.apply { from(rootProject.file("gradle/dependencies.gradle.kts")) }
54
repositories {
65
google()
76
jcenter()
87
maven("https://jitpack.io")
98
}
109
dependencies {
11-
classpath(kotlin("gradle-plugin", extra["versions.kotlin"] as String))
12-
classpath(extra["plugins.android"] as String)
13-
classpath(extra["plugins.androidMaven"] as String)
14-
classpath(extra["plugins.bintray"] as String)
15-
classpath(extra["plugins.dcendentsMaven"] as String)
16-
classpath(extra["plugins.versions"] as String)
10+
classpath(Libs.kotlin_gradle_plugin)
11+
classpath(Libs.com_android_tools_build_gradle)
12+
classpath(Libs.android_maven_publish)
13+
classpath(Libs.gradle_bintray_plugin)
14+
classpath(Libs.android_maven_gradle_plugin)
15+
classpath(Libs.gradle_versions_plugin)
1716
}
1817
}
1918

20-
// Populate deployment credentials in an environment-aware fashion.
21-
//
22-
// * Local development:
23-
// Stored in local.properties file on the machine
24-
// * CI Server:
25-
// Stored in environment variables before launch
26-
val properties = Properties().apply {
27-
val credentialsFile = File(project.rootDir, "local.properties")
28-
if (credentialsFile.exists()) {
29-
load(credentialsFile.inputStream())
30-
}
19+
plugins {
20+
id("de.fayard.buildSrcVersions") version "0.3.2"
3121
}
3222

33-
internal val bintrayUser = properties.getProperty("BINTRAY_USER", System.getenv("bintrayUser"))
34-
internal val bintrayKey = properties.getProperty("BINTRAY_KEY", System.getenv("bintrayKey"))
35-
internal val sonatypeUser = properties.getProperty("SONATYPE_USER", System.getenv("sonatypeUser"))
36-
internal val sonatypePass = properties.getProperty("SONATYPE_PASS", System.getenv("sonatypePass"))
37-
3823
allprojects {
3924
repositories {
4025
google()
4126
jcenter()
4227
maven("https://oss.sonatype.org/content/repositories/snapshots")
4328
}
4429

45-
// Store deployment credentials
46-
extra["deployment.bintrayUser"] = bintrayUser
47-
extra["deployment.bintrayKey"] = bintrayKey
48-
extra["deployment.sonatypeUser"] = sonatypeUser
49-
extra["deployment.sonatypePass"] = sonatypePass
50-
51-
apply(from = "$rootDir/gradle/dependencies.gradle.kts")
30+
// Store deployment credentials (used in deployment.gradle)
31+
extra["deployCredentials"] = DeployCredentials(project)
5232
}

buildSrc/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
.gradle/
3+
build/

buildSrc/settings.gradle.kts

Whitespace-only changes.
Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package de.mannodermaus.gradle.plugins.junit5
2-
3-
import de.mannodermaus.gradle.plugins.junit5.Platform.Android
4-
import de.mannodermaus.gradle.plugins.junit5.Platform.Java
1+
import Platform.Android
2+
import Platform.Java
3+
import org.gradle.api.Project
4+
import java.io.File
5+
import java.util.*
56

67
sealed class Platform(val name: String) {
78
object Java : Platform("java")
@@ -12,7 +13,7 @@ sealed class Platform(val name: String) {
1213
* Encapsulation for "deployable" library artifacts,
1314
* containing all sorts of configuration related to Maven coordinates, for instance.
1415
*/
15-
open class Artifact internal constructor(
16+
class Deployed internal constructor(
1617
val platform: Platform,
1718
val groupId: String,
1819
val artifactId: String,
@@ -30,7 +31,7 @@ object Artifacts {
3031
/**
3132
* Gradle Plugin artifact
3233
*/
33-
val Plugin = Artifact(
34+
val Plugin = Deployed(
3435
platform = Java,
3536
groupId = "de.mannodermaus.gradle.plugins",
3637
artifactId = "android-junit5",
@@ -48,7 +49,7 @@ object Artifacts {
4849
private val currentVersion = "0.2.3-SNAPSHOT"
4950
val latestStableVersion = "0.2.2"
5051

51-
val Library = Artifact(
52+
val Library = Deployed(
5253
platform = Android(minSdk = 26),
5354
groupId = groupId,
5455
artifactId = "android-instrumentation-test",
@@ -58,7 +59,7 @@ object Artifacts {
5859
description = "Extensions for instrumented Android tests with JUnit 5."
5960
)
6061

61-
val Runner = Artifact(
62+
val Runner = Deployed(
6263
platform = Android(minSdk = 14),
6364
groupId = groupId,
6465
artifactId = "android-instrumentation-test-runner",
@@ -69,3 +70,31 @@ object Artifacts {
6970
)
7071
}
7172
}
73+
74+
class DeployCredentials(private val project: Project) {
75+
76+
val bintrayUser: String?
77+
val bintrayKey: String?
78+
val sonatypeUser: String?
79+
val sonatypePass: String?
80+
81+
init {
82+
// Populate deployment credentials in an environment-aware fashion.
83+
//
84+
// * Local development:
85+
// Stored in local.properties file on the machine
86+
// * CI Server:
87+
// Stored in environment variables before launch
88+
val properties = Properties().apply {
89+
val credentialsFile = File(project.rootDir, "local.properties")
90+
if (credentialsFile.exists()) {
91+
load(credentialsFile.inputStream())
92+
}
93+
}
94+
95+
this.bintrayUser = properties.getProperty("BINTRAY_USER", System.getenv("bintrayUser"))
96+
this.bintrayKey = properties.getProperty("BINTRAY_KEY", System.getenv("bintrayKey"))
97+
this.sonatypeUser = properties.getProperty("SONATYPE_USER", System.getenv("sonatypeUser"))
98+
this.sonatypePass = properties.getProperty("SONATYPE_PASS", System.getenv("sonatypePass"))
99+
}
100+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Android {
2+
const val buildToolsVersion = "28.0.3"
3+
const val compileSdkVersion = "android-28"
4+
const val javaMaxHeapSize = "3g"
5+
6+
const val targetSdkVersion = 28
7+
const val sampleMinSdkVersion = 14
8+
val runnerMinSdkVersion = (Artifacts.Instrumentation.Runner.platform as Platform.Android).minSdk
9+
val instrumentationMinSdkVersion = (Artifacts.Instrumentation.Library.platform as Platform.Android).minSdk
10+
}

0 commit comments

Comments
 (0)