Skip to content

Commit d4037f9

Browse files
Merge pull request #134 from dropbox/jfein/add-java-services
Support java modules better
2 parents e023b57 + c6c11b7 commit d4037f9

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
5353
}
5454

5555
private fun registerJvmTests(project: Project) {
56-
registerAffectedTestTask(TestType.JvmTest("runAffectedUnitTests", TASK_GROUP_NAME, "Runs all affected unit tests"), project)
56+
registerAffectedTestTask(TestType.AndroidJvmTest("runAffectedUnitTests", TASK_GROUP_NAME, "Runs all affected unit tests"), project)
5757
}
5858

5959
private fun registerAffectedConnectedTestTask(rootProject: Project) {
@@ -74,11 +74,11 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
7474

7575
rootProject.subprojects { project ->
7676
project.afterEvaluate {
77-
val pluginIds = setOf("com.android.application", "com.android.library", "java-library", "kotlin")
77+
val pluginIds = setOf("com.android.application", "com.android.library", "java", "kotlin")
7878
pluginIds.forEach { pluginId ->
79-
if (pluginId == "java-library" || pluginId == "kotlin") {
80-
if (testType is TestType.JvmTest ) {
81-
withPlugin(pluginId, task, testType, project)
79+
if (pluginId == "java" || pluginId == "kotlin") {
80+
if (testType is TestType.AndroidJvmTest ) {
81+
withPlugin(pluginId, task, TestType.JvmTest(testType.name, testType.group, testType.description), project)
8282
}
8383
} else {
8484
withPlugin(pluginId, task, testType, project)
@@ -117,7 +117,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
117117
return when (testType) {
118118
is TestType.RunAndroidTest -> getPathAndTask(project, tasks.runAndroidTestTask)
119119
is TestType.AssembleAndroidTest -> getPathAndTask(project, tasks.assembleAndroidTestTask)
120-
is TestType.JvmTest -> getPathAndTask(project, tasks.jvmTestTask)
120+
is TestType.AndroidJvmTest -> getPathAndTask(project, tasks.jvmTestTask)
121+
is TestType.JvmTest -> {
122+
// if we are a jvm only module, run the "test" command by default unless a custom one is set
123+
if (tasks.jvmTestTask != AffectedTestConfiguration.DEFAULT_JVM_TEST_TASK) {
124+
getPathAndTask(project, tasks.jvmTestTask)
125+
} else {
126+
getPathAndTask(project, "test")
127+
}
128+
}
121129
}
122130
}
123131

@@ -166,6 +174,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
166174
internal sealed class TestType(open val name: String, open val group: String, open val description: String) {
167175
data class RunAndroidTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description)
168176
data class AssembleAndroidTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description)
177+
data class AndroidJvmTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description)
169178
data class JvmTest(override val name: String, override val group: String, override val description: String) : TestType(name, group, description)
170179
}
171180

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ open class AffectedTestConfiguration {
1010

1111
var assembleAndroidTestTask : String? = "assembleDebugAndroidTest"
1212
var runAndroidTestTask : String? = "connectedDebugAndroidTest"
13-
var jvmTestTask : String? = "testDebugUnitTest"
13+
var jvmTestTask : String? = DEFAULT_JVM_TEST_TASK
1414

1515
companion object {
1616
const val name = "affectedTestConfiguration"
17+
internal const val DEFAULT_JVM_TEST_TASK = "testDebugUnitTest"
1718
}
1819
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id("java-library")
3+
id("org.jetbrains.kotlin.jvm")
4+
}
5+
6+
java {
7+
sourceCompatibility = JavaVersion.VERSION_1_8
8+
targetCompatibility = JavaVersion.VERSION_1_8
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.dropbox.sample_jvm_module
2+
3+
class MyClass {
4+
}

sample/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include ':sample-app'
22
include ':sample-core'
3+
include ':sample-jvm-module'
34
include ':sample-util'

0 commit comments

Comments
 (0)