Add test to check kaptGenerateStub and KotlinCompiler have same module-name

^KT-55334
This commit is contained in:
Yahor Berdnikau
2022-12-13 15:13:28 +01:00
committed by Space Team
parent c4f83adc2a
commit 189ef3425f
4 changed files with 66 additions and 0 deletions
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.*
import org.junit.jupiter.api.DisplayName
import kotlin.io.path.appendText
import kotlin.io.path.readText
import kotlin.io.path.writeText
@DisplayName("android with kapt3 tests")
@@ -291,4 +292,39 @@ class Kapt3AndroidIT : Kapt3BaseIT() {
)
}
}
@DisplayName("KT-55334: Kapt generate stubs and related KotlinCompile tasks are using similar -module-name value")
@GradleAndroidTest
fun kaptGenerateStubsModuleName(
gradleVersion: GradleVersion,
agpVersion: String,
jdkVersion: JdkVersions.ProvidedJdk
) {
project(
"kapt2/android-dagger",
gradleVersion,
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion),
buildJdk = jdkVersion.location
) {
build(":app:compileDebugAndroidTestKotlin") {
val stubsFile = subProject("app")
.projectPath
.resolve("build/tmp/kapt3/stubs/debugAndroidTest/com/example/dagger/kotlin/TestClass.java")
assertFileExists(stubsFile)
assertFileContains(
stubsFile,
"public final void bar${'$'}app_debugAndroidTest() {"
)
val compiledClassFile = subProject("app")
.projectPath
.resolve("build/tmp/kotlin-classes/debugAndroidTest/com/example/dagger/kotlin/TestClass.class")
assertFileExists(compiledClassFile)
checkBytecodeContains(
compiledClassFile.toFile(),
"public final bar${'$'}app_debugAndroidTest()V"
)
}
}
}
}
@@ -36,5 +36,7 @@ dependencies {
implementation 'com.google.dagger:dagger:2.9'
kapt 'com.google.dagger:dagger-compiler:2.9'
kapt 'javax.annotation:javax.annotation-api:1.3.2'
kaptAndroidTest 'com.google.dagger:dagger-compiler:2.9'
kaptAndroidTest 'javax.annotation:javax.annotation-api:1.3.2'
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
}
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package com.example.dagger.kotlin
class TestClass {
internal fun bar() {
}
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package com.example.dagger.kotlin
import com.example.dagger.kotlin.ui.HomeActivity
import dagger.Component
import javax.inject.Singleton
@Singleton
@Component
interface TestComponent {
fun inject(application: BaseApplication)
}