diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt index 291848ac..6ddf9c0c 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt @@ -53,7 +53,7 @@ class AffectedModuleDetectorPlugin : Plugin { } private fun registerJvmTests(project: Project) { - registerAffectedTestTask(TestType.JvmTest("runAffectedUnitTests", TASK_GROUP_NAME, "Runs all affected unit tests"), project) + registerAffectedTestTask(TestType.AndroidJvmTest("runAffectedUnitTests", TASK_GROUP_NAME, "Runs all affected unit tests"), project) } private fun registerAffectedConnectedTestTask(rootProject: Project) { @@ -74,11 +74,11 @@ class AffectedModuleDetectorPlugin : Plugin { rootProject.subprojects { project -> project.afterEvaluate { - val pluginIds = setOf("com.android.application", "com.android.library", "java-library", "kotlin") + val pluginIds = setOf("com.android.application", "com.android.library", "java", "kotlin") pluginIds.forEach { pluginId -> - if (pluginId == "java-library" || pluginId == "kotlin") { - if (testType is TestType.JvmTest ) { - withPlugin(pluginId, task, testType, project) + if (pluginId == "java" || pluginId == "kotlin") { + if (testType is TestType.AndroidJvmTest ) { + withPlugin(pluginId, task, TestType.JvmTest(testType.name, testType.group, testType.description), project) } } else { withPlugin(pluginId, task, testType, project) @@ -117,7 +117,15 @@ class AffectedModuleDetectorPlugin : Plugin { return when (testType) { is TestType.RunAndroidTest -> getPathAndTask(project, tasks.runAndroidTestTask) is TestType.AssembleAndroidTest -> getPathAndTask(project, tasks.assembleAndroidTestTask) - is TestType.JvmTest -> getPathAndTask(project, tasks.jvmTestTask) + is TestType.AndroidJvmTest -> getPathAndTask(project, tasks.jvmTestTask) + is TestType.JvmTest -> { + // if we are a jvm only module, run the "test" command by default unless a custom one is set + if (tasks.jvmTestTask != AffectedTestConfiguration.DEFAULT_JVM_TEST_TASK) { + getPathAndTask(project, tasks.jvmTestTask) + } else { + getPathAndTask(project, "test") + } + } } } @@ -166,6 +174,7 @@ class AffectedModuleDetectorPlugin : Plugin { internal sealed class TestType(open val name: String, open val group: String, open val description: String) { data class RunAndroidTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description) data class AssembleAndroidTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description) + data class AndroidJvmTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description) data class JvmTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description) } diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt index f11a26fe..15f89a56 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt @@ -10,9 +10,10 @@ open class AffectedTestConfiguration { var assembleAndroidTestTask : String? = "assembleDebugAndroidTest" var runAndroidTestTask : String? = "connectedDebugAndroidTest" - var jvmTestTask : String? = "testDebugUnitTest" + var jvmTestTask : String? = DEFAULT_JVM_TEST_TASK companion object { const val name = "affectedTestConfiguration" + internal const val DEFAULT_JVM_TEST_TASK = "testDebugUnitTest" } } \ No newline at end of file diff --git a/sample/sample-jvm-module/.gitignore b/sample/sample-jvm-module/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/sample/sample-jvm-module/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/sample/sample-jvm-module/build.gradle.kts b/sample/sample-jvm-module/build.gradle.kts new file mode 100644 index 00000000..e8259cee --- /dev/null +++ b/sample/sample-jvm-module/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("java-library") + id("org.jetbrains.kotlin.jvm") +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} \ No newline at end of file diff --git a/sample/sample-jvm-module/src/main/java/com/dropbox/sample_jvm_module/MyClass.kt b/sample/sample-jvm-module/src/main/java/com/dropbox/sample_jvm_module/MyClass.kt new file mode 100644 index 00000000..a6145fde --- /dev/null +++ b/sample/sample-jvm-module/src/main/java/com/dropbox/sample_jvm_module/MyClass.kt @@ -0,0 +1,4 @@ +package com.dropbox.sample_jvm_module + +class MyClass { +} \ No newline at end of file diff --git a/sample/settings.gradle b/sample/settings.gradle index 36e414ba..1ea3d634 100644 --- a/sample/settings.gradle +++ b/sample/settings.gradle @@ -1,3 +1,4 @@ include ':sample-app' include ':sample-core' +include ':sample-jvm-module' include ':sample-util' \ No newline at end of file