Fix Kapt-generated sources not compiled by jvm.withJava(), KT-32804

Given that the Kapt subplugin creates new tasks, it is impossible
to run it in the context of lazy task configuration. Disable lazy
task configuration for Kotlin/JVM by always accessing the task
instance until subplugins are refactored to be able to properly
work with task configuration avoidance.
This commit is contained in:
Sergey Igushkin
2019-09-02 20:55:13 +03:00
parent 0456220f7a
commit f2d2fb9e6b
3 changed files with 48 additions and 12 deletions
@@ -315,12 +315,31 @@ class NewMultiplatformIT : BaseGradleIT() {
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
apply plugin: 'kotlin-kapt' // Check that Kapts works, generates and compiles sources
mainClassName = 'com.example.lib.CommonKt'
dependencies {
jvm6MainImplementation("com.google.dagger:dagger:2.24")
kapt("com.google.dagger:dagger-compiler:2.24")
}
""".trimIndent()
)
}
// Check Kapt:
projectDir.resolve("src/jvm6Main/kotlin/Main.kt").appendText(
"\n" + """
interface Iface
@dagger.Module
object Module {
@JvmStatic @dagger.Provides
fun provideHeater(): Iface = object : Iface { }
}
""".trimIndent()
)
fun javaSourceRootForCompilation(compilationName: String) =
if (testJavaSupportInJvmTargets) "src/jvm6${compilationName.capitalize()}/java" else "src/$compilationName/java"
@@ -372,6 +391,12 @@ class NewMultiplatformIT : BaseGradleIT() {
assertSuccessful()
val expectedMainClasses =
classesWithoutJava + setOf(
// classes for Kapt test:
"java/main/com/example/lib/Module_ProvideHeaterFactory.class",
"kotlin/jvm6/main/com/example/lib/Module\$provideHeater\$1.class",
"kotlin/jvm6/main/com/example/lib/Iface.class",
"kotlin/jvm6/main/com/example/lib/Module.class",
// other added classes:
"kotlin/jvm6/main/com/example/lib/KotlinClassInJava.class",
"java/main/com/example/lib/JavaClassInJava.class",
"java/test/com/example/lib/JavaTest.class"
@@ -381,7 +406,10 @@ class NewMultiplatformIT : BaseGradleIT() {
val jvmTestTaskName = if (testJavaSupportInJvmTargets) "jvm6Test" else "test"
assertTasksExecuted(":$jvmTestTaskName")
assertFileExists("build/reports/tests/allTests/classes/com.example.lib.JavaTest.html")
if (testJavaSupportInJvmTargets) {
assertFileExists("build/reports/tests/allTests/classes/com.example.lib.JavaTest.html")
}
if (testJavaSupportInJvmTargets) {
assertNotContains(KotlinJvmWithJavaTargetPreset.DEPRECATION_WARNING)
@@ -2111,4 +2139,4 @@ class NewMultiplatformIT : BaseGradleIT() {
checkIntegrationTestOutput(nativeHostTargetName)
}
}
}
}