diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3AndroidIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3AndroidIT.kt index 3f27901eca8d5..92eacd76e31bd 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3AndroidIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3AndroidIT.kt @@ -10,6 +10,7 @@ import org.junit.Assume import org.junit.Ignore import org.junit.Test import java.io.File +import kotlin.test.assertTrue open class Kapt3Android41IT : Kapt3AndroidIT() { override val androidGradlePluginVersion: AGPVersion @@ -439,6 +440,34 @@ abstract class Kapt3AndroidIT : BaseGradleIT() { } } + // KT-55334: Kapt generate stubs and related compile task use same -module-name value + @Test + fun kaptGenerateStubsModuleName() { + with( + Project( + "android-dagger", + directoryPrefix = "kapt2", + minLogLevel = LogLevel.DEBUG + ) + ) { + build(":app:compileDebugAndroidTestKotlin") { + val stubsFile = projectDir + .resolve("app/build/tmp/kapt3/stubs/debugAndroidTest/com/example/dagger/kotlin/TestClass.java") + assertTrue(stubsFile.exists(), "File does not exist: ${stubsFile.absolutePath}") + assertTrue( + stubsFile.readText() + .contains("public final void bar${'$'}app_debug() {"), + "Actual generated stub content:\n${stubsFile.readText()}" + ) + + val compilerClassFile = projectDir + .resolve("app/build/tmp/kotlin-classes/debugAndroidTest/com/example/dagger/kotlin/TestClass.class") + assertTrue(compilerClassFile.exists(), "File does not exist: ${compilerClassFile.absolutePath}") + checkBytecodeContains(compilerClassFile, "public final bar${'$'}app_debug()V") + } + } + } + private fun setupDataBinding(project: Project) { project.setupWorkingDir() diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index 5ea9ede9e7473..44fac2691bc09 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -1781,7 +1781,7 @@ class NewMultiplatformIT : BaseGradleIT() { "Hello.internalFun\$new_mpp_associate_compilations", "HelloTest.internalTestFun\$new_mpp_associate_compilations" ) - assertFileExists("build/classes/kotlin/jvm/integrationTest/META-INF/new-mpp-associate-compilations_integrationTest.kotlin_module") + assertFileExists("build/classes/kotlin/jvm/integrationTest/META-INF/new-mpp-associate-compilations.kotlin_module") // JS: assertFileExists( diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/build.gradle index a2b6df11083f9..e4f67982bd859 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/build.gradle @@ -35,5 +35,8 @@ 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' } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/src/androidTest/java/com/example/dagger/kotlin/TestClass.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/src/androidTest/java/com/example/dagger/kotlin/TestClass.kt new file mode 100644 index 0000000000000..8502f89ce3805 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/src/androidTest/java/com/example/dagger/kotlin/TestClass.kt @@ -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() { + + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/src/androidTest/java/com/example/dagger/kotlin/TestComponent.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/src/androidTest/java/com/example/dagger/kotlin/TestComponent.kt new file mode 100644 index 0000000000000..abacc9e720a80 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/src/androidTest/java/com/example/dagger/kotlin/TestComponent.kt @@ -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) +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentsContributor.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentsContributor.kt index 4d88ddc343065..c9ac5ae64809d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentsContributor.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentsContributor.kt @@ -98,5 +98,9 @@ internal open class KotlinJvmCompilerArgumentsContributor( args.destinationAsFile = destinationDir compilerOptions.fillCompilerArguments(args) + // Restoring moduleName overwritten by fillCompilerArguments default value + if (args.moduleName == null) { + args.moduleName = moduleName + } } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt index 48e173be4bd22..e5387c92c3569 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt @@ -123,5 +123,9 @@ abstract class KaptGenerateStubsTask @Inject constructor( args.verbose = verbose.get() args.classpathAsList = this.libraries.filter { it.exists() }.toList() args.destinationAsFile = this.destinationDirectory.get().asFile + // Setting moduleName from task input if it has default complierOptions value + if (args.moduleName == null) { + args.moduleName = moduleName.get() + } } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 6af4c32c5b0f8..ca2c087b25c2a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -538,7 +538,6 @@ abstract class KotlinCompile @Inject constructor( UsesKotlinJavaToolchain { init { - compilerOptions.moduleName.convention(moduleName) compilerOptions.verbose.convention(logger.isDebugEnabled) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinCompileConfig.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinCompileConfig.kt index 09898a13b70b5..23a3635990885 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinCompileConfig.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinCompileConfig.kt @@ -75,7 +75,7 @@ internal open class BaseKotlinCompileConfig : AbstractKotl task.associatedJavaCompileTaskTargetCompatibility.value(javaTaskProvider.map { it.targetCompatibility }) task.associatedJavaCompileTaskName.value(javaTaskProvider.map { it.name }) task.ownModuleName.value( - (compilation.compilerOptions.options as KotlinJvmCompilerOptions).moduleName.convention(compilation.ownModuleName) + (compilation.compilerOptions.options as KotlinJvmCompilerOptions).moduleName.orElse(compilation.ownModuleName) ) } }