Ensure tasks using android sdk or android jar have proper dependencies
A test task, that uses android dependency but does not depend on a corresponding configuration, would fail when it was run after 'clean' task. I've extracted 'useAndroidSdk', 'useAndroidJar' extensions making it harder for a developer to forget to set up task dependencies.
This commit is contained in:
@@ -24,6 +24,7 @@ import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.task
|
||||
import org.gradle.kotlin.dsl.the
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import java.lang.Character.isLowerCase
|
||||
import java.lang.Character.isUpperCase
|
||||
|
||||
@@ -81,3 +82,28 @@ private inline fun String.isFirstChar(f: (Char) -> Boolean) = isNotEmpty() && f(
|
||||
|
||||
inline fun <reified T : Task> Project.getOrCreateTask(taskName: String, body: T.() -> Unit): T =
|
||||
(tasks.findByName(taskName)?.let { it as T } ?: task<T>(taskName)).apply { body() }
|
||||
|
||||
private fun Test.useAndroidConfiguration(systemPropertyName: String, configName: String) {
|
||||
val configuration = with(project) {
|
||||
configurations.getOrCreate(configName)
|
||||
.also {
|
||||
dependencies.add(
|
||||
configName,
|
||||
dependencies.project(":custom-dependencies:android-sdk", configuration = configName)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
dependsOn(configuration)
|
||||
doFirst {
|
||||
systemProperty(systemPropertyName, configuration.singleFile.canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
fun Test.useAndroidSdk() {
|
||||
useAndroidConfiguration(systemPropertyName = "android.sdk", configName = "androidSdk")
|
||||
}
|
||||
|
||||
fun Test.useAndroidJar() {
|
||||
useAndroidConfiguration(systemPropertyName = "android.jar", configName = "androidJar")
|
||||
}
|
||||
@@ -3,8 +3,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
apply { plugin("kotlin") }
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
|
||||
dependencies {
|
||||
testRuntime(intellijDep())
|
||||
|
||||
@@ -59,8 +57,6 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("junit"))
|
||||
testRuntime(intellijPluginDep("maven"))
|
||||
testRuntime(intellijPluginDep("testng"))
|
||||
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -69,10 +65,9 @@ sourceSets {
|
||||
}
|
||||
|
||||
projectTest {
|
||||
dependsOn(androidSdk)
|
||||
workingDir = rootDir
|
||||
useAndroidSdk()
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
systemProperty("idea.home.path", intellijRootDir().canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
apply { plugin("kotlin") }
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
|
||||
dependencies {
|
||||
testRuntime(intellijDep())
|
||||
|
||||
@@ -46,8 +44,6 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("coverage")) { includeJars("jacocoant") }
|
||||
testRuntime(intellijPluginDep("maven"))
|
||||
testRuntime(intellijPluginDep("android"))
|
||||
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -62,9 +58,8 @@ testsJar()
|
||||
|
||||
projectTest {
|
||||
workingDir = rootDir
|
||||
dependsOn(androidSdk)
|
||||
useAndroidSdk()
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
systemProperty("idea.home.path", intellijRootDir().canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
configurations {
|
||||
androidSdk
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile project(':kotlin-gradle-plugin')
|
||||
testCompile project(':kotlin-gradle-plugin').sourceSets.test.output
|
||||
@@ -29,8 +25,6 @@ dependencies {
|
||||
testCompile gradleApi()
|
||||
|
||||
testRuntime project(path: ':kotlin-android-extensions', configuration: 'runtimeJar')
|
||||
|
||||
androidSdk project(path: ":custom-dependencies:android-sdk", configuration: "androidSdk")
|
||||
}
|
||||
|
||||
// Include Gradle task properties validation into the testing procedure:
|
||||
@@ -87,9 +81,8 @@ tasks.withType(Test) {
|
||||
if (mavenLocalRepo != null) {
|
||||
systemProperty("maven.repo.local", mavenLocalRepo)
|
||||
}
|
||||
doFirst {
|
||||
systemProperty("android.sdk", project.configurations["androidSdk"].singleFile.getCanonicalPath())
|
||||
}
|
||||
|
||||
TasksKt.useAndroidSdk(it)
|
||||
|
||||
testLogging {
|
||||
// set options for log level LIFECYCLE
|
||||
|
||||
@@ -4,7 +4,6 @@ description = "Kotlin Android Extensions Compiler"
|
||||
apply { plugin("kotlin") }
|
||||
|
||||
val robolectricClasspath by configurations.creating
|
||||
val androidJar by configurations.creating
|
||||
|
||||
dependencies {
|
||||
testCompile(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
@@ -30,7 +29,6 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("junit")) { includeJars("idea-junit", "resources_en") }
|
||||
|
||||
robolectricClasspath(commonDep("org.robolectric", "robolectric"))
|
||||
androidJar(project(":custom-dependencies:android-sdk", configuration = "androidJar"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -54,10 +52,10 @@ projectTest {
|
||||
environment("ANDROID_EXTENSIONS_RUNTIME_CLASSES", getSourceSetsFrom(":kotlin-android-extensions-runtime")["main"].output.classesDirs.asPath)
|
||||
dependsOn(":dist")
|
||||
workingDir = rootDir
|
||||
useAndroidJar()
|
||||
doFirst {
|
||||
val androidPluginPath = File(intellijRootDir(), "plugins/android").canonicalPath
|
||||
systemProperty("ideaSdk.androidPlugin.path", androidPluginPath)
|
||||
systemProperty("robolectric.classpath", robolectricClasspath.asPath)
|
||||
systemProperty("android.jar", androidJar.singleFile.canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@ apply { plugin("kotlin") }
|
||||
|
||||
jvmTarget = "1.6"
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
val androidJar by configurations.creating
|
||||
|
||||
dependencies {
|
||||
testRuntime(intellijDep())
|
||||
|
||||
@@ -53,9 +50,6 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("java-decompiler"))
|
||||
testRuntime(intellijPluginDep("maven"))
|
||||
testRuntime(intellijPluginDep("android"))
|
||||
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
androidJar(project(":custom-dependencies:android-sdk", configuration = "androidJar"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -67,11 +61,10 @@ testsJar {}
|
||||
|
||||
projectTest {
|
||||
dependsOn(":kotlin-android-extensions-runtime:dist")
|
||||
dependsOn(androidSdk)
|
||||
workingDir = rootDir
|
||||
useAndroidSdk()
|
||||
useAndroidJar()
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
systemProperty("android.jar", androidJar.singleFile.canonicalPath)
|
||||
systemProperty("idea.home.path", intellijRootDir().canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
apply { plugin("kotlin") }
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
|
||||
dependencies {
|
||||
testRuntime(intellijDep())
|
||||
|
||||
@@ -25,8 +23,6 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("android"))
|
||||
testRuntime(intellijDep("jps-build-test"))
|
||||
testRuntime(intellijDep("jps-standalone"))
|
||||
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -36,8 +32,8 @@ sourceSets {
|
||||
|
||||
projectTest {
|
||||
workingDir = rootDir
|
||||
useAndroidSdk()
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
systemProperty("idea.home.path", intellijRootDir().canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user