From 61a11663f8bc1a204db0ccccc315269252d040cf Mon Sep 17 00:00:00 2001 From: Marcel Schnelle Date: Mon, 31 Dec 2018 00:48:50 +0100 Subject: [PATCH] Type-safe config access (#137) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .circleci/config.yml | 2 +- android-junit5-tests/build.gradle.kts | 58 +++--- android-junit5/build.gradle.kts | 17 +- build.gradle.kts | 40 +--- buildSrc/.gitignore | 3 + buildSrc/settings.gradle.kts | 0 .../junit5/BuildArtifacts.kt => Artifacts.kt} | 45 ++++- buildSrc/src/main/kotlin/Environment.kt | 10 + buildSrc/src/main/kotlin/Libs.kt | 181 ++++++++++++++++++ .../gradle/plugins/junit5 => }/Tasks.kt | 2 - buildSrc/src/main/kotlin/Versions.kt | 76 ++++++++ gradle/dependencies.gradle.kts | 68 ------- gradle/deployment.gradle | 23 +-- instrumentation-runner/build.gradle.kts | 40 ++-- instrumentation/build.gradle.kts | 42 ++-- sample/build.gradle.kts | 37 ++-- 16 files changed, 414 insertions(+), 230 deletions(-) create mode 100644 buildSrc/.gitignore create mode 100644 buildSrc/settings.gradle.kts rename buildSrc/src/main/kotlin/{de/mannodermaus/gradle/plugins/junit5/BuildArtifacts.kt => Artifacts.kt} (60%) create mode 100644 buildSrc/src/main/kotlin/Environment.kt create mode 100644 buildSrc/src/main/kotlin/Libs.kt rename buildSrc/src/main/kotlin/{de/mannodermaus/gradle/plugins/junit5 => }/Tasks.kt (95%) create mode 100644 buildSrc/src/main/kotlin/Versions.kt delete mode 100644 gradle/dependencies.gradle.kts diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a3434e4..5a8d5862 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ defaults: &defaults GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError"' cache_key: &cache_key - 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" }} + 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" }} version: 2 jobs: diff --git a/android-junit5-tests/build.gradle.kts b/android-junit5-tests/build.gradle.kts index 8f0242b8..f4926b7a 100644 --- a/android-junit5-tests/build.gradle.kts +++ b/android-junit5-tests/build.gradle.kts @@ -1,11 +1,9 @@ -import de.mannodermaus.gradle.plugins.junit5.WriteClasspathResource import org.apache.tools.ant.filters.ReplaceTokens import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id("groovy") - id("java-gradle-plugin") id("java-library") id("idea") id("jacoco") @@ -55,10 +53,10 @@ configurations { val processTestResources = tasks.getByName("processTestResources") as Copy processTestResources.apply { val tokens = mapOf( - "COMPILE_SDK_VERSION" to project.extra["android.compileSdkVersion"] as String, - "BUILD_TOOLS_VERSION" to project.extra["android.buildToolsVersion"] as String, - "MIN_SDK_VERSION" to (project.extra["android.sampleMinSdkVersion"] as Int).toString(), - "TARGET_SDK_VERSION" to (project.extra["android.targetSdkVersion"] as Int).toString() + "COMPILE_SDK_VERSION" to Android.compileSdkVersion, + "BUILD_TOOLS_VERSION" to Android.buildToolsVersion, + "MIN_SDK_VERSION" to Android.sampleMinSdkVersion.toString(), + "TARGET_SDK_VERSION" to Android.targetSdkVersion.toString() ) inputs.properties(tokens) @@ -76,44 +74,42 @@ tasks.withType { events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) exceptionFormat = TestExceptionFormat.FULL } - - // Uncomment this line to run disable running Functional Tests on the local device -// environment("CI", "true") } dependencies { testImplementation(project(":android-junit5")) - testImplementation(kotlin("gradle-plugin", extra["versions.kotlin"] as String)) - testImplementation(extra["plugins.android"] as String) - testImplementation(extra["libs.commonsIO"] as String) - testImplementation(extra["libs.commonsLang"] as String) - testImplementation(extra["libs.junit4"] as String) - testImplementation(extra["libs.junitJupiterApi"] as String) - testImplementation(extra["libs.junitJupiterParams"] as String) - testImplementation(extra["libs.spekApi"] as String) - testImplementation(extra["libs.junitPioneer"] as String) - testImplementation(extra["libs.assertjCore"] as String) - testImplementation(extra["libs.mockito"] as String) - - testRuntimeOnly(extra["libs.junitJupiterEngine"] as String) - testRuntimeOnly(extra["libs.junitVintageEngine"] as String) - testRuntimeOnly(extra["libs.spekEngine"] as String) + testImplementation(gradleTestKit()) + testImplementation(Libs.kotlin_gradle_plugin) + testImplementation(Libs.com_android_tools_build_gradle) + testImplementation(Libs.commons_io) + testImplementation(Libs.commons_lang) + testImplementation(Libs.junit) + testImplementation(Libs.junit_jupiter_api) + testImplementation(Libs.junit_jupiter_params) + testImplementation(Libs.spek_api) + testImplementation(Libs.junit_pioneer) + testImplementation(Libs.assertj_core) + testImplementation(Libs.mockito_core) + + testRuntimeOnly(Libs.junit_jupiter_engine) + testRuntimeOnly(Libs.junit_vintage_engine) + testRuntimeOnly(Libs.spek_junit_platform_engine) // Compilation of local classpath for functional tests val functionalTest by configurations - functionalTest(kotlin("compiler-embeddable", extra["versions.kotlin"] as String)) - functionalTest(extra["libs.junit4"] as String) - functionalTest(extra["libs.junitJupiterApi"] as String) - functionalTest(extra["libs.junitJupiterEngine"] as String) + functionalTest(Libs.kotlin_compiler_embeddable) + functionalTest(Libs.junit) + functionalTest(Libs.junit_jupiter_api) + functionalTest(Libs.junit_jupiter_engine) val functionalTestAgp32X by configurations - functionalTestAgp32X(extra["plugins.android.32X"] as String) + functionalTestAgp32X("com.android.tools.build:gradle:3.2.1") val functionalTestAgp33X by configurations - functionalTestAgp33X(extra["plugins.android.33X"] as String) + functionalTestAgp33X("com.android.tools.build:gradle:3.3.0-rc03") val functionalTestAgp34X by configurations - functionalTestAgp34X(extra["plugins.android.34X"] as String) + functionalTestAgp34X("com.android.tools.build:gradle:3.4.0-alpha09") } // Resource Writers diff --git a/android-junit5/build.gradle.kts b/android-junit5/build.gradle.kts index 5cc263d8..aa3be068 100644 --- a/android-junit5/build.gradle.kts +++ b/android-junit5/build.gradle.kts @@ -1,5 +1,3 @@ -import de.mannodermaus.gradle.plugins.junit5.Artifact -import de.mannodermaus.gradle.plugins.junit5.Artifacts import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -55,18 +53,19 @@ gradlePlugin { // ------------------------------------------------------------------------------------------------ dependencies { - compileOnly(kotlin("gradle-plugin", extra["versions.kotlin"] as String)) - implementation(kotlin("stdlib-jdk8", extra["versions.kotlin"] as String)) + compileOnly(Libs.kotlin_gradle_plugin) + implementation(gradleApi()) - implementation(extra["libs.javaSemver"] as String) - implementation(extra["libs.annimonStream"] as String) - implementation(extra["libs.junitPlatformCommons"] as String) - implementation(extra["plugins.android"] as String) + implementation(Libs.kotlin_stdlib_jdk8) + implementation(Libs.java_semver) + implementation(Libs.stream) + implementation(Libs.junit_platform_commons) + implementation(Libs.com_android_tools_build_gradle) } // ------------------------------------------------------------------------------------------------ // Deployment Setup // ------------------------------------------------------------------------------------------------ -val deployConfig by extra { Artifacts.Plugin } +val deployConfig by extra { Artifacts.Plugin } apply(from = "$rootDir/gradle/deployment.gradle") diff --git a/build.gradle.kts b/build.gradle.kts index 3dd98520..9c5748e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,40 +1,25 @@ import java.util.Properties buildscript { - rootProject.apply { from(rootProject.file("gradle/dependencies.gradle.kts")) } repositories { google() jcenter() maven("https://jitpack.io") } dependencies { - classpath(kotlin("gradle-plugin", extra["versions.kotlin"] as String)) - classpath(extra["plugins.android"] as String) - classpath(extra["plugins.androidMaven"] as String) - classpath(extra["plugins.bintray"] as String) - classpath(extra["plugins.dcendentsMaven"] as String) - classpath(extra["plugins.versions"] as String) + classpath(Libs.kotlin_gradle_plugin) + classpath(Libs.com_android_tools_build_gradle) + classpath(Libs.android_maven_publish) + classpath(Libs.gradle_bintray_plugin) + classpath(Libs.android_maven_gradle_plugin) + classpath(Libs.gradle_versions_plugin) } } -// Populate deployment credentials in an environment-aware fashion. -// -// * Local development: -// Stored in local.properties file on the machine -// * CI Server: -// Stored in environment variables before launch -val properties = Properties().apply { - val credentialsFile = File(project.rootDir, "local.properties") - if (credentialsFile.exists()) { - load(credentialsFile.inputStream()) - } +plugins { + id("de.fayard.buildSrcVersions") version "0.3.2" } -internal val bintrayUser = properties.getProperty("BINTRAY_USER", System.getenv("bintrayUser")) -internal val bintrayKey = properties.getProperty("BINTRAY_KEY", System.getenv("bintrayKey")) -internal val sonatypeUser = properties.getProperty("SONATYPE_USER", System.getenv("sonatypeUser")) -internal val sonatypePass = properties.getProperty("SONATYPE_PASS", System.getenv("sonatypePass")) - allprojects { repositories { google() @@ -42,11 +27,6 @@ allprojects { maven("https://oss.sonatype.org/content/repositories/snapshots") } - // Store deployment credentials - extra["deployment.bintrayUser"] = bintrayUser - extra["deployment.bintrayKey"] = bintrayKey - extra["deployment.sonatypeUser"] = sonatypeUser - extra["deployment.sonatypePass"] = sonatypePass - - apply(from = "$rootDir/gradle/dependencies.gradle.kts") + // Store deployment credentials (used in deployment.gradle) + extra["deployCredentials"] = DeployCredentials(project) } diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore new file mode 100644 index 00000000..ea958e57 --- /dev/null +++ b/buildSrc/.gitignore @@ -0,0 +1,3 @@ + +.gradle/ +build/ diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 00000000..e69de29b diff --git a/buildSrc/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/BuildArtifacts.kt b/buildSrc/src/main/kotlin/Artifacts.kt similarity index 60% rename from buildSrc/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/BuildArtifacts.kt rename to buildSrc/src/main/kotlin/Artifacts.kt index 28f3e0ea..85d617e1 100644 --- a/buildSrc/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/BuildArtifacts.kt +++ b/buildSrc/src/main/kotlin/Artifacts.kt @@ -1,7 +1,8 @@ -package de.mannodermaus.gradle.plugins.junit5 - -import de.mannodermaus.gradle.plugins.junit5.Platform.Android -import de.mannodermaus.gradle.plugins.junit5.Platform.Java +import Platform.Android +import Platform.Java +import org.gradle.api.Project +import java.io.File +import java.util.* sealed class Platform(val name: String) { object Java : Platform("java") @@ -12,7 +13,7 @@ sealed class Platform(val name: String) { * Encapsulation for "deployable" library artifacts, * containing all sorts of configuration related to Maven coordinates, for instance. */ -open class Artifact internal constructor( +class Deployed internal constructor( val platform: Platform, val groupId: String, val artifactId: String, @@ -30,7 +31,7 @@ object Artifacts { /** * Gradle Plugin artifact */ - val Plugin = Artifact( + val Plugin = Deployed( platform = Java, groupId = "de.mannodermaus.gradle.plugins", artifactId = "android-junit5", @@ -48,7 +49,7 @@ object Artifacts { private val currentVersion = "0.2.3-SNAPSHOT" val latestStableVersion = "0.2.2" - val Library = Artifact( + val Library = Deployed( platform = Android(minSdk = 26), groupId = groupId, artifactId = "android-instrumentation-test", @@ -58,7 +59,7 @@ object Artifacts { description = "Extensions for instrumented Android tests with JUnit 5." ) - val Runner = Artifact( + val Runner = Deployed( platform = Android(minSdk = 14), groupId = groupId, artifactId = "android-instrumentation-test-runner", @@ -69,3 +70,31 @@ object Artifacts { ) } } + +class DeployCredentials(private val project: Project) { + + val bintrayUser: String? + val bintrayKey: String? + val sonatypeUser: String? + val sonatypePass: String? + + init { + // Populate deployment credentials in an environment-aware fashion. + // + // * Local development: + // Stored in local.properties file on the machine + // * CI Server: + // Stored in environment variables before launch + val properties = Properties().apply { + val credentialsFile = File(project.rootDir, "local.properties") + if (credentialsFile.exists()) { + load(credentialsFile.inputStream()) + } + } + + this.bintrayUser = properties.getProperty("BINTRAY_USER", System.getenv("bintrayUser")) + this.bintrayKey = properties.getProperty("BINTRAY_KEY", System.getenv("bintrayKey")) + this.sonatypeUser = properties.getProperty("SONATYPE_USER", System.getenv("sonatypeUser")) + this.sonatypePass = properties.getProperty("SONATYPE_PASS", System.getenv("sonatypePass")) + } +} diff --git a/buildSrc/src/main/kotlin/Environment.kt b/buildSrc/src/main/kotlin/Environment.kt new file mode 100644 index 00000000..06a1a82f --- /dev/null +++ b/buildSrc/src/main/kotlin/Environment.kt @@ -0,0 +1,10 @@ +object Android { + const val buildToolsVersion = "28.0.3" + const val compileSdkVersion = "android-28" + const val javaMaxHeapSize = "3g" + + const val targetSdkVersion = 28 + const val sampleMinSdkVersion = 14 + val runnerMinSdkVersion = (Artifacts.Instrumentation.Runner.platform as Platform.Android).minSdk + val instrumentationMinSdkVersion = (Artifacts.Instrumentation.Library.platform as Platform.Android).minSdk +} diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt new file mode 100644 index 00000000..292fa2c2 --- /dev/null +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -0,0 +1,181 @@ +import kotlin.String + +/** + * Generated by https://github.com/jmfayard/buildSrcVersions + * + * Update this file with + * `$ ./gradlew buildSrcVersions` */ +object Libs { + /** + * https://developer.android.com/testing */ + const val espresso_core: String = "com.android.support.test.espresso:espresso-core:" + + Versions.espresso_core + + /** + * https://developer.android.com/testing */ + const val com_android_support_test_runner: String = "com.android.support.test:runner:" + + Versions.com_android_support_test_runner + + /** + * https://developer.android.com/studio */ + const val aapt2: String = "com.android.tools.build:aapt2:" + Versions.aapt2 + + /** + * https://developer.android.com/studio */ + const val com_android_tools_build_gradle: String = "com.android.tools.build:gradle:" + + Versions.com_android_tools_build_gradle + + /** + * https://developer.android.com/studio */ + const val lint_gradle: String = "com.android.tools.lint:lint-gradle:" + Versions.lint_gradle + + /** + * https://github.com/aNNiMON/Lightweight-Stream-API */ + const val stream: String = "com.annimon:stream:" + Versions.stream + + /** + * https://github.com/ben-manes/gradle-versions-plugin */ + const val gradle_versions_plugin: String = "com.github.ben-manes:gradle-versions-plugin:" + + Versions.gradle_versions_plugin + + /** + * https://github.com/dcendents/android-maven-gradle-plugin */ + const val android_maven_gradle_plugin: String = + "com.github.dcendents:android-maven-gradle-plugin:" + + Versions.android_maven_gradle_plugin + + /** + * https://github.com/zafarkhaja/jsemver */ + const val java_semver: String = "com.github.zafarkhaja:java-semver:" + Versions.java_semver + + const val gradle_bintray_plugin: String = "com.jfrog.bintray.gradle:gradle-bintray-plugin:" + + Versions.gradle_bintray_plugin + + /** + * http://github.com/square/assertj-android/ */ + const val assertj_android: String = "com.squareup.assertj:assertj-android:" + + Versions.assertj_android + + /** + * http://commons.apache.org/proper/commons-io/ */ + const val commons_io: String = "commons-io:commons-io:" + Versions.commons_io + + /** + * http://commons.apache.org/lang/ */ + const val commons_lang: String = "commons-lang:commons-lang:" + Versions.commons_lang + + const val de_fayard_buildsrcversions_gradle_plugin: String = + "de.fayard.buildSrcVersions:de.fayard.buildSrcVersions.gradle.plugin:" + + Versions.de_fayard_buildsrcversions_gradle_plugin + + const val android_junit5: String = "de.mannodermaus.gradle.plugins:android-junit5:" + + Versions.android_junit5 + + const val android_instrumentation_test_runner: String = + "de.mannodermaus.junit5:android-instrumentation-test-runner:" + + Versions.de_mannodermaus_junit5 + + const val android_instrumentation_test: String = + "de.mannodermaus.junit5:android-instrumentation-test:" + Versions.de_mannodermaus_junit5 + + /** + * https://github.com/wupdigital/android-maven-publish */ + const val android_maven_publish: String = "digital.wup:android-maven-publish:" + + Versions.android_maven_publish + + /** + * http://junit.org */ + const val junit: String = "junit:junit:" + Versions.junit + + /** + * http://assertj.org */ + const val assertj_core: String = "org.assertj:assertj-core:" + Versions.assertj_core + + /** + * https://kotlinlang.org/ */ + const val kotlin_compiler_embeddable: String = + "org.jetbrains.kotlin:kotlin-compiler-embeddable:" + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ */ + const val kotlin_gradle_plugin: String = "org.jetbrains.kotlin:kotlin-gradle-plugin:" + + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ */ + const val kotlin_reflect: String = "org.jetbrains.kotlin:kotlin-reflect:" + + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ */ + const val kotlin_scripting_compiler_embeddable: String = + "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:" + + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ */ + const val kotlin_stdlib_jdk8: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:" + + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ */ + const val kotlin_stdlib: String = "org.jetbrains.kotlin:kotlin-stdlib:" + + Versions.org_jetbrains_kotlin + + /** + * https://jetbrains.github.io/spek */ + const val spek_api: String = "org.jetbrains.spek:spek-api:" + Versions.org_jetbrains_spek + + /** + * https://jetbrains.github.io/spek */ + const val spek_junit_platform_engine: String = + "org.jetbrains.spek:spek-junit-platform-engine:" + Versions.org_jetbrains_spek + + /** + * https://github.com/junit-pioneer/junit-pioneer */ + const val junit_pioneer: String = "org.junit-pioneer:junit-pioneer:" + Versions.junit_pioneer + + /** + * http://junit.org/junit5/ */ + const val junit_jupiter_api: String = "org.junit.jupiter:junit-jupiter-api:" + + Versions.org_junit_jupiter + + /** + * http://junit.org/junit5/ */ + const val junit_jupiter_engine: String = "org.junit.jupiter:junit-jupiter-engine:" + + Versions.org_junit_jupiter + + /** + * http://junit.org/junit5/ */ + const val junit_jupiter_params: String = "org.junit.jupiter:junit-jupiter-params:" + + Versions.org_junit_jupiter + + /** + * http://junit.org/junit5/ */ + const val junit_platform_commons: String = "org.junit.platform:junit-platform-commons:" + + Versions.org_junit_platform + + /** + * http://junit.org/junit5/ */ + const val junit_platform_engine: String = "org.junit.platform:junit-platform-engine:" + + Versions.org_junit_platform + + /** + * http://junit.org/junit5/ */ + const val junit_platform_launcher: String = "org.junit.platform:junit-platform-launcher:" + + Versions.org_junit_platform + + /** + * http://junit.org/junit5/ */ + const val junit_platform_runner: String = "org.junit.platform:junit-platform-runner:" + + Versions.org_junit_platform + + /** + * http://junit.org/junit5/ */ + const val junit_vintage_engine: String = "org.junit.vintage:junit-vintage-engine:" + + Versions.junit_vintage_engine + + /** + * https://github.com/mockito/mockito */ + const val mockito_core: String = "org.mockito:mockito-core:" + Versions.mockito_core +} diff --git a/buildSrc/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Tasks.kt b/buildSrc/src/main/kotlin/Tasks.kt similarity index 95% rename from buildSrc/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Tasks.kt rename to buildSrc/src/main/kotlin/Tasks.kt index f09d6b9b..21a42d33 100644 --- a/buildSrc/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Tasks.kt +++ b/buildSrc/src/main/kotlin/Tasks.kt @@ -1,5 +1,3 @@ -package de.mannodermaus.gradle.plugins.junit5 - import org.gradle.api.DefaultTask import org.gradle.api.file.FileCollection import org.gradle.api.tasks.InputFiles diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 00000000..dce64f3a --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,76 @@ +import kotlin.String + +/** + * Find which updates are available by running + * `$ ./gradlew buildSrcVersions` + * This will only update the comments. + * + * YOU are responsible for updating manually the dependency version. */ +object Versions { + const val espresso_core: String = "3.0.1" // available: "3.0.2" + + const val com_android_support_test_runner: String = "1.0.2" + + const val aapt2: String = "3.2.1-4818971" + + const val com_android_tools_build_gradle: String = "3.2.1" + + const val lint_gradle: String = "26.2.1" + + const val stream: String = "1.2.1" + + const val gradle_versions_plugin: String = "0.20.0" + + const val android_maven_gradle_plugin: String = "2.1" + + const val java_semver: String = "0.9.0" + + const val gradle_bintray_plugin: String = "1.8.4" + + const val assertj_android: String = "1.2.0" + + const val commons_io: String = "2.6" + + const val commons_lang: String = "2.6" + + const val de_fayard_buildsrcversions_gradle_plugin: String = "0.3.2" + + const val android_junit5: String = "1.3.2.0-SNAPSHOT" + + const val de_mannodermaus_junit5: String = "0.2.2" + + const val android_maven_publish: String = "3.6.2" + + const val junit: String = "4.12" + + const val assertj_core: String = "3.11.1" + + const val org_jetbrains_kotlin: String = "1.3.11" + + const val org_jetbrains_spek: String = "1.2.1" + + const val junit_pioneer: String = "0.2.2" // available: "0.3.0" + + const val org_junit_jupiter: String = "5.3.2" + + const val org_junit_platform: String = "1.3.2" + + const val junit_vintage_engine: String = "5.3.2" + + const val mockito_core: String = "2.19.0" // available: "2.23.4" + + /** + * + * To update Gradle, edit the wrapper file at path: + * ./gradle/wrapper/gradle-wrapper.properties + */ + object Gradle { + const val runningVersion: String = "5.0" + + const val currentVersion: String = "5.0" + + const val nightlyVersion: String = "5.2-20181230000028+0000" + + const val releaseCandidate: String = "5.1-rc-3" + } +} diff --git a/gradle/dependencies.gradle.kts b/gradle/dependencies.gradle.kts deleted file mode 100644 index 3bb7f0d4..00000000 --- a/gradle/dependencies.gradle.kts +++ /dev/null @@ -1,68 +0,0 @@ -import de.mannodermaus.gradle.plugins.junit5.Artifacts -import de.mannodermaus.gradle.plugins.junit5.Platform.Android - -// Latest Stable Versions of this plugin -extra["android-junit5.plugin.latestVersion"] = Artifacts.Plugin.latestStableVersion -extra["android-junit5.instrumentation.latestVersion"] = Artifacts.Instrumentation.latestStableVersion -extra["android-junit5.instrumentation.runner.artifactId"] = Artifacts.Instrumentation.Runner.artifactId - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// Android Environment -// A Note to my forgetful self: -// -// When updating these values, make sure -// to always update the CI config, too -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -extra["android.buildToolsVersion"] = "28.0.3" -extra["android.compileSdkVersion"] = "android-28" -extra["android.javaMaxHeapSize"] = "3g" -extra["android.targetSdkVersion"] = 28 -extra["android.sampleMinSdkVersion"] = 14 -extra["android.runnerMinSdkVersion"] = (Artifacts.Instrumentation.Runner.platform as Android).minSdk -extra["android.instrumentationMinSdkVersion"] = (Artifacts.Instrumentation.Library.platform as Android).minSdk - -// Common properties -val apacheCommonsVersion = "2.6" -val junitPlatformVersion = "1.3.2" -val junitJupiterVersion = "5.3.2" -val junitVintageVersion = "5.3.2" -val kotlinVersion = "1.3.11" -val spekVersion = "1.2.1" - -// Dependencies: Plugins -extra["plugins.android.32X"] = "com.android.tools.build:gradle:3.2.1" -extra["plugins.android.33X"] = "com.android.tools.build:gradle:3.3.0-rc03" -extra["plugins.android.34X"] = "com.android.tools.build:gradle:3.4.0-alpha09" -extra["plugins.android"] = extra["plugins.android.32X"] - -extra["plugins.androidMaven"] = "digital.wup:android-maven-publish:3.6.2" -extra["plugins.bintray"] = "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" -extra["plugins.dcendentsMaven"] = "com.github.dcendents:android-maven-gradle-plugin:2.1" -extra["plugins.versions"] = "com.github.ben-manes:gradle-versions-plugin:0.20.0" - -// Dependencies: Libraries -extra["libs.annimonStream"] = "com.annimon:stream:1.2.1" -extra["libs.javaSemver"] = "com.github.zafarkhaja:java-semver:0.9.0" - -extra["libs.androidTestRunner"] = "com.android.support.test:runner:1.0.2" -extra["libs.assertjAndroid"] = "com.squareup.assertj:assertj-android:1.2.0" -extra["libs.assertjCore"] = "org.assertj:assertj-core:3.11.1" -extra["libs.commonsIO"] = "commons-io:commons-io:$apacheCommonsVersion" -extra["libs.commonsLang"] = "commons-lang:commons-lang:$apacheCommonsVersion" -extra["libs.espresso"] = "com.android.support.test.espresso:espresso-core:3.0.1" -extra["libs.junit4"] = "junit:junit:4.12" -extra["libs.junitJupiterApi"] = "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion" -extra["libs.junitJupiterEngine"] = "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion" -extra["libs.junitJupiterParams"] = "org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion" -extra["libs.junitPioneer"] = "org.junit-pioneer:junit-pioneer:0.2.2" -extra["libs.junitPlatformCommons"] = "org.junit.platform:junit-platform-commons:$junitPlatformVersion" -extra["libs.junitPlatformEngine"] = "org.junit.platform:junit-platform-engine:$junitPlatformVersion" -extra["libs.junitPlatformLauncher"] = "org.junit.platform:junit-platform-launcher:$junitPlatformVersion" -extra["libs.junitPlatformRunner"] = "org.junit.platform:junit-platform-runner:$junitPlatformVersion" -extra["libs.junitVintageEngine"] = "org.junit.vintage:junit-vintage-engine:$junitVintageVersion" -extra["libs.mockito"] = "org.mockito:mockito-core:2.19.0" -extra["libs.spekApi"] = "org.jetbrains.spek:spek-api:$spekVersion" -extra["libs.spekEngine"] = "org.jetbrains.spek:spek-junit-platform-engine:$spekVersion" - -// Versions -extra["versions.kotlin"] = kotlinVersion diff --git a/gradle/deployment.gradle b/gradle/deployment.gradle index dee5aa53..2973f40b 100644 --- a/gradle/deployment.gradle +++ b/gradle/deployment.gradle @@ -1,26 +1,15 @@ -import de.mannodermaus.gradle.plugins.junit5.Artifacts - // Common logic shared across modules whose artifacts are provided to jCenter and Sonatype OSS. // // This script expects an extra named "deployConfig" to exist on the Project instance. // Its type is defined within the buildSrc module of this project. -/** Obtains a required parameter from a Map, or throws an Exception if it's absent */ -private def required(Map config, String property) { - def value = config.get(property, null) - if (!value) { - throw new IllegalStateException( - "Deployment for module '$name' is missing required parameter '$property'") - } - return value -} - // Access Map properties if (!project.ext.has("deployConfig")) { throw new IllegalStateException("Deployed module '$name' requires a 'deployConfig'") } -final de.mannodermaus.gradle.plugins.junit5.Artifact deployConfig = project.ext.deployConfig +final def deployConfig = project.ext.deployConfig +final def deployCredentials = project.ext.deployCredentials final String targetPlatform = deployConfig.platform.name final String groupId = deployConfig.groupId final String artifactId = deployConfig.artifactId @@ -125,8 +114,8 @@ project.configure(project) { maven { name "snapshot" credentials { - username project.ext["deployment.sonatypeUser"] - password project.ext["deployment.sonatypePass"] + username deployCredentials.sonatypeUser + password deployCredentials.sonatypePass } url "https://oss.sonatype.org/content/repositories/snapshots" } @@ -142,8 +131,8 @@ project.configure(project) { } project.bintray { - user = project.ext["deployment.bintrayUser"] - key = project.ext["deployment.bintrayKey"] + user = deployCredentials.bintrayUser + key = deployCredentials.bintrayKey configurations = ["archives"] dryRun = false publish = true diff --git a/instrumentation-runner/build.gradle.kts b/instrumentation-runner/build.gradle.kts index 41187ba4..2b64103b 100644 --- a/instrumentation-runner/build.gradle.kts +++ b/instrumentation-runner/build.gradle.kts @@ -1,5 +1,3 @@ -import de.mannodermaus.gradle.plugins.junit5.Artifact -import de.mannodermaus.gradle.plugins.junit5.Artifacts import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { @@ -10,7 +8,7 @@ buildscript { } dependencies { - val latest = extra["android-junit5.plugin.latestVersion"] + val latest = Artifacts.Plugin.latestStableVersion classpath("de.mannodermaus.gradle.plugins:android-junit5:$latest") } } @@ -25,15 +23,15 @@ apply { } android { - compileSdkVersion(extra["android.compileSdkVersion"] as String) + compileSdkVersion(Android.compileSdkVersion) dexOptions { - javaMaxHeapSize = extra["android.javaMaxHeapSize"] as String + javaMaxHeapSize = Android.javaMaxHeapSize } defaultConfig { - minSdkVersion(extra["android.runnerMinSdkVersion"] as Int) - targetSdkVersion(extra["android.targetSdkVersion"] as Int) + minSdkVersion(Android.runnerMinSdkVersion) + targetSdkVersion(Android.targetSdkVersion) versionCode = 1 versionName = "1.0" } @@ -76,30 +74,30 @@ configurations.all { // that's kind of deep. // To avoid conflicts, prefer using the local classes // and exclude the dependency from being pulled in externally. - exclude(module = extra["android-junit5.instrumentation.runner.artifactId"] as String) + exclude(module = Artifacts.Instrumentation.Runner.artifactId) } dependencies { - implementation(kotlin("stdlib", extra["versions.kotlin"] as String)) - implementation(kotlin("reflect", extra["versions.kotlin"] as String)) - implementation(extra["libs.junit4"] as String) + implementation(Libs.kotlin_stdlib) + implementation(Libs.kotlin_reflect) + implementation(Libs.junit) // This module's JUnit 5 dependencies cannot be present on the runtime classpath, // since that would prematurely raise the minSdkVersion requirement for target applications, // even though not all product flavors might want to use JUnit 5. // Therefore, only compile against those APIs, and have them provided at runtime // by the "instrumentation" companion library instead. - compileOnly(extra["libs.junitJupiterApi"] as String) - compileOnly(extra["libs.junitJupiterParams"] as String) - compileOnly(extra["libs.junitPlatformRunner"] as String) + compileOnly(Libs.junit_jupiter_api) + compileOnly(Libs.junit_jupiter_params) + compileOnly(Libs.junit_platform_runner) - testImplementation(extra["libs.assertjCore"] as String) - testImplementation(extra["libs.mockito"] as String) - testImplementation(extra["libs.junitJupiterApi"] as String) - testImplementation(extra["libs.junitJupiterParams"] as String) - testImplementation(extra["libs.junitPlatformRunner"] as String) + testImplementation(Libs.assertj_core) + testImplementation(Libs.mockito_core) + testImplementation(Libs.junit_jupiter_api) + testImplementation(Libs.junit_jupiter_params) + testImplementation(Libs.junit_platform_runner) - testRuntimeOnly(extra["libs.junitJupiterEngine"] as String) + testRuntimeOnly(Libs.junit_jupiter_engine) } // ------------------------------------------------------------------------------------------------ @@ -109,5 +107,5 @@ dependencies { // This section defines the necessary tasks to push new releases and snapshots using Gradle tasks. // ------------------------------------------------------------------------------------------------ -val deployConfig by extra { Artifacts.Instrumentation.Runner } +val deployConfig by extra { Artifacts.Instrumentation.Runner } apply(from = "$rootDir/gradle/deployment.gradle") diff --git a/instrumentation/build.gradle.kts b/instrumentation/build.gradle.kts index 52ec529e..5f90c1a5 100644 --- a/instrumentation/build.gradle.kts +++ b/instrumentation/build.gradle.kts @@ -1,5 +1,3 @@ -import de.mannodermaus.gradle.plugins.junit5.Artifact -import de.mannodermaus.gradle.plugins.junit5.Artifacts import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -8,15 +6,15 @@ plugins { } android { - compileSdkVersion(extra["android.compileSdkVersion"] as String) + compileSdkVersion(Android.compileSdkVersion) dexOptions { - javaMaxHeapSize = extra["android.javaMaxHeapSize"] as String + javaMaxHeapSize = Android.javaMaxHeapSize } defaultConfig { - minSdkVersion(extra["android.instrumentationMinSdkVersion"] as Int) - targetSdkVersion(extra["android.targetSdkVersion"] as Int) + minSdkVersion(Android.instrumentationMinSdkVersion) + targetSdkVersion(Android.targetSdkVersion) versionCode = 1 versionName = "1.0" multiDexEnabled = true @@ -66,32 +64,32 @@ configurations { } dependencies { - implementation(kotlin("stdlib", extra["versions.kotlin"] as String)) - implementation(extra["libs.androidTestRunner"] as String) - implementation(extra["libs.junitJupiterApi"] as String) + implementation(Libs.kotlin_stdlib) + implementation(Libs.com_android_support_test_runner) + implementation(Libs.junit_jupiter_api) // This is required by the "instrumentation-runner" companion library, // since it can't provide any JUnit 5 runtime libraries itself // due to fear of prematurely incrementing the minSdkVersion requirement. - runtimeOnly(extra["libs.junitPlatformRunner"] as String) + runtimeOnly(Libs.junit_platform_runner) - commonTestImplementation(extra["libs.assertjCore"] as String) - commonTestImplementation(extra["libs.mockito"] as String) - commonTestImplementation(extra["libs.junitJupiterApi"] as String) - commonTestImplementation(extra["libs.junitJupiterEngine"] as String) + commonTestImplementation(Libs.assertj_core) + commonTestImplementation(Libs.mockito_core) + commonTestImplementation(Libs.junit_jupiter_api) + commonTestImplementation(Libs.junit_jupiter_engine) - androidTestImplementation(extra["libs.assertjAndroid"] as String) - androidTestImplementation(extra["libs.espresso"] as String) + androidTestImplementation(Libs.assertj_android) + androidTestImplementation(Libs.espresso_core) androidTestRuntimeOnly(project(":instrumentation-runner")) // Obviously, these dependencies should be mostly "runtimeOnly", // but we have to override bundled APIs from the IDE as much as possible for Android Studio. - testImplementation(extra["libs.junitPlatformEngine"] as String) - testImplementation(extra["libs.junitPlatformLauncher"] as String) - testImplementation(extra["libs.junitJupiterApi"] as String) - testImplementation(extra["libs.junitJupiterEngine"] as String) - testImplementation(extra["libs.junitVintageEngine"] as String) + testImplementation(Libs.junit_platform_engine) + testImplementation(Libs.junit_platform_launcher) + testImplementation(Libs.junit_jupiter_api) + testImplementation(Libs.junit_jupiter_engine) + testImplementation(Libs.junit_vintage_engine) } // ------------------------------------------------------------------------------------------------ @@ -101,5 +99,5 @@ dependencies { // This section defines the necessary tasks to push new releases and snapshots using Gradle tasks. // ------------------------------------------------------------------------------------------------ -val deployConfig by extra { Artifacts.Instrumentation.Library } +val deployConfig by extra { Artifacts.Instrumentation.Library } apply(from = "$rootDir/gradle/deployment.gradle") diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 0041740e..295d21bc 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -2,8 +2,6 @@ import de.mannodermaus.gradle.plugins.junit5.junitPlatform import org.gradle.api.tasks.testing.logging.TestLogEvent buildscript { - rootProject.apply { from(rootProject.file("gradle/dependencies.gradle.kts")) } - repositories { google() jcenter() @@ -11,7 +9,7 @@ buildscript { } dependencies { - val latest = extra["android-junit5.plugin.latestVersion"] + val latest = Artifacts.Plugin.latestStableVersion classpath("de.mannodermaus.gradle.plugins:android-junit5:$latest") } } @@ -27,16 +25,16 @@ apply { } android { - compileSdkVersion(extra["android.compileSdkVersion"] as String) + compileSdkVersion(Android.compileSdkVersion) dexOptions { - javaMaxHeapSize = extra["android.javaMaxHeapSize"] as String + javaMaxHeapSize = Android.javaMaxHeapSize } defaultConfig { applicationId = "de.mannodermaus.junit5.sample" - minSdkVersion(extra["android.sampleMinSdkVersion"] as Int) - targetSdkVersion(extra["android.targetSdkVersion"] as Int) + minSdkVersion(Android.sampleMinSdkVersion) + targetSdkVersion(Android.targetSdkVersion) versionCode = 1 versionName = "1.0" @@ -88,27 +86,24 @@ tasks.withType { } dependencies { - implementation(kotlin("stdlib", extra["versions.kotlin"] as String)) + implementation(Libs.kotlin_stdlib) - testImplementation(extra["libs.junitJupiterApi"] as String) - testImplementation(extra["libs.junitJupiterParams"] as String) - testRuntimeOnly(extra["libs.junitJupiterEngine"] as String) + testImplementation(Libs.junit_jupiter_api) + testImplementation(Libs.junit_jupiter_params) + testRuntimeOnly(Libs.junit_jupiter_engine) - androidTestImplementation(extra["libs.junit4"] as String) - androidTestImplementation(extra["libs.androidTestRunner"] as String) + androidTestImplementation(Libs.junit) + androidTestImplementation(Libs.com_android_support_test_runner) // Add the Android Instrumentation Test dependencies to the product flavor only // (with this, only the "experimental" flavor must have minSdkVersion 26) - val latestVersion = extra["android-junit5.instrumentation.latestVersion"] val androidTestExperimentalImplementation by configurations - androidTestExperimentalImplementation(extra["libs.junitJupiterApi"] as String) - androidTestExperimentalImplementation( - "de.mannodermaus.junit5:android-instrumentation-test:$latestVersion") + androidTestExperimentalImplementation(Libs.junit_jupiter_api) + androidTestExperimentalImplementation(Libs.android_instrumentation_test) // Runtime dependencies for Android Instrumentation Tests val androidTestExperimentalRuntimeOnly by configurations - androidTestExperimentalRuntimeOnly(extra["libs.junitJupiterEngine"] as String) - androidTestExperimentalRuntimeOnly(extra["libs.junitPlatformRunner"] as String) - androidTestExperimentalRuntimeOnly( - "de.mannodermaus.junit5:android-instrumentation-test-runner:$latestVersion") + androidTestExperimentalRuntimeOnly(Libs.junit_jupiter_engine) + androidTestExperimentalRuntimeOnly(Libs.junit_platform_runner) + androidTestExperimentalRuntimeOnly(Libs.android_instrumentation_test_runner) }