Fix for androidTest Gradle build
Replaced adding Kotlin sources with dependency on copy*KotlinClasses, which might not be called since Android Gradle plugin sometimes bypasses the tasks in finalizedBy . Added a test for androidTest build apart from general build. Issues: #KT-16897 Fixed
This commit is contained in:
+12
@@ -73,6 +73,18 @@ abstract class AbstractKotlinAndroidGradleTests(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testAssembleAndroidTestFirst() {
|
||||||
|
val project = Project("AndroidProject", gradleVersion)
|
||||||
|
|
||||||
|
// Execute 'assembleAndroidTest' first, without 'build' side effects
|
||||||
|
project.build("assembleAndroidTest") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains(":copyFlavor1DebugKotlinClasses")
|
||||||
|
assertContains(":copyFlavor2DebugKotlinClasses")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIncrementalCompile() {
|
fun testIncrementalCompile() {
|
||||||
val project = Project("AndroidIncrementalSingleModuleProject", gradleVersion)
|
val project = Project("AndroidIncrementalSingleModuleProject", gradleVersion)
|
||||||
|
|||||||
+3
@@ -23,5 +23,8 @@ class InternalDummyApplicationTest : ApplicationTestCase<Application>(Applicatio
|
|||||||
init {
|
init {
|
||||||
val dummy = InternalDummy("World")
|
val dummy = InternalDummy("World")
|
||||||
assert("Hello World!" == dummy.greeting) { "Expected: 'Hello World!'. Actual value: ${dummy.greeting}" }
|
assert("Hello World!" == dummy.greeting) { "Expected: 'Hello World!'. Actual value: ${dummy.greeting}" }
|
||||||
|
|
||||||
|
// Check that the Java sources from the tested variant are available
|
||||||
|
val bar = foo.FooJavaClass()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-7
@@ -458,14 +458,16 @@ internal open class KotlinAndroidPlugin(
|
|||||||
variantDataName, rootKotlinOptions, subpluginEnvironment, tasksProvider)
|
variantDataName, rootKotlinOptions, subpluginEnvironment, tasksProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
configureSources(kotlinTask, variantData)
|
for (task in listOfNotNull(kotlinTask, kotlinAfterJavaTask)) {
|
||||||
if (isAndroidTestVariant) {
|
configureSources(task, variantData)
|
||||||
configureSources(kotlinTask, testedVariantData!!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kotlinAfterJavaTask != null) {
|
if (isAndroidTestVariant) {
|
||||||
configureSources(kotlinAfterJavaTask, variantData)
|
// Android Gradle plugin bypasses the Gradle finalizedBy for its tasks in some cases, and
|
||||||
|
// the Kotlin classes may not be copied for the tested variant. Make sure they are.
|
||||||
|
kotlinTask.dependsOn(syncOutputTaskName(testedVariantData!!.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
appliedPlugins
|
appliedPlugins
|
||||||
.flatMap { it.getSubpluginKotlinTasks(project, kotlinTask) }
|
.flatMap { it.getSubpluginKotlinTasks(project, kotlinTask) }
|
||||||
.forEach { configureSources(it, variantData) }
|
.forEach { configureSources(it, variantData) }
|
||||||
@@ -485,7 +487,8 @@ internal open class KotlinAndroidPlugin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureSources(compileTask: AbstractCompile, variantData: BaseVariantData<out BaseVariantOutputData>) {
|
private fun configureSources(compileTask: AbstractCompile,
|
||||||
|
variantData: BaseVariantData<out BaseVariantOutputData>) {
|
||||||
val logger = compileTask.project.logger
|
val logger = compileTask.project.logger
|
||||||
|
|
||||||
for (provider in variantData.sourceProviders) {
|
for (provider in variantData.sourceProviders) {
|
||||||
@@ -542,6 +545,8 @@ private fun configureJavaTask(kotlinTask: KotlinCompile, javaTask: AbstractCompi
|
|||||||
javaTask.appendClasspathDynamically(kotlinTask.destinationDir!!)
|
javaTask.appendClasspathDynamically(kotlinTask.destinationDir!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun syncOutputTaskName(variantName: String) = "copy${variantName.capitalize()}KotlinClasses"
|
||||||
|
|
||||||
private fun createSyncOutputTask(
|
private fun createSyncOutputTask(
|
||||||
project: Project,
|
project: Project,
|
||||||
kotlinTask: KotlinCompile,
|
kotlinTask: KotlinCompile,
|
||||||
@@ -553,7 +558,7 @@ private fun createSyncOutputTask(
|
|||||||
val kotlinCompile = kotlinAfterJavaTask ?: kotlinTask
|
val kotlinCompile = kotlinAfterJavaTask ?: kotlinTask
|
||||||
val kotlinDir = kotlinCompile.destinationDir
|
val kotlinDir = kotlinCompile.destinationDir
|
||||||
val javaDir = javaTask.destinationDir
|
val javaDir = javaTask.destinationDir
|
||||||
val taskName = "copy${variantName.capitalize()}KotlinClasses"
|
val taskName = syncOutputTaskName(variantName)
|
||||||
|
|
||||||
val syncTask = project.tasks.create(taskName, SyncOutputTask::class.java)
|
val syncTask = project.tasks.create(taskName, SyncOutputTask::class.java)
|
||||||
syncTask.kotlinOutputDir = kotlinDir
|
syncTask.kotlinOutputDir = kotlinDir
|
||||||
|
|||||||
Reference in New Issue
Block a user