Skip to content

Commit

Permalink
Merge pull request #134 from dropbox/jfein/add-java-services
Browse files Browse the repository at this point in the history
Support java modules better
  • Loading branch information
joshafeinberg authored Apr 14, 2022
2 parents e023b57 + c6c11b7 commit d4037f9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
}

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) {
Expand All @@ -74,11 +74,11 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {

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)
Expand Down Expand Up @@ -117,7 +117,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
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")
}
}
}
}

Expand Down Expand Up @@ -166,6 +174,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions sample/sample-jvm-module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
9 changes: 9 additions & 0 deletions sample/sample-jvm-module/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("java-library")
id("org.jetbrains.kotlin.jvm")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.dropbox.sample_jvm_module

class MyClass {
}
1 change: 1 addition & 0 deletions sample/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include ':sample-app'
include ':sample-core'
include ':sample-jvm-module'
include ':sample-util'

0 comments on commit d4037f9

Please sign in to comment.