Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52b225d

Browse files
committed
Fix task module-name is not propagated to compiler arguments
Currently, we have three ways to set '-module-name' compiler argument:- via KotlinCompilation.compilerOptions.options.moduleName- via KotlinCompile.compilerOptions.moduleName- via KotlinCompile.moduleNameLast one was ignored and overwritten by compilerOptions when they arefilling arguments leading to wrong argument in case of Android UI testscompilation.^KT-55334 Fixed
1 parentd40ebc3 commit52b225d

File tree

9 files changed

+70
-3
lines changed

9 files changed

+70
-3
lines changed

‎libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3AndroidIT.kt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.junit.Assume
1010
importorg.junit.Ignore
1111
importorg.junit.Test
1212
importjava.io.File
13+
importkotlin.test.assertTrue
1314

1415
openclassKapt3Android41IT :Kapt3AndroidIT() {
1516
overrideval androidGradlePluginVersion:AGPVersion
@@ -439,6 +440,34 @@ abstract class Kapt3AndroidIT : BaseGradleIT() {
439440
}
440441
}
441442

443+
// KT-55334: Kapt generate stubs and related compile task use same -module-name value
444+
@Test
445+
funkaptGenerateStubsModuleName() {
446+
with(
447+
Project(
448+
"android-dagger",
449+
directoryPrefix="kapt2",
450+
minLogLevel=LogLevel.DEBUG
451+
)
452+
) {
453+
build(":app:compileDebugAndroidTestKotlin") {
454+
val stubsFile= projectDir
455+
.resolve("app/build/tmp/kapt3/stubs/debugAndroidTest/com/example/dagger/kotlin/TestClass.java")
456+
assertTrue(stubsFile.exists(),"File does not exist:${stubsFile.absolutePath}")
457+
assertTrue(
458+
stubsFile.readText()
459+
.contains("public final void bar${'$'}app_debug() {"),
460+
"Actual generated stub content:\n${stubsFile.readText()}"
461+
)
462+
463+
val compilerClassFile= projectDir
464+
.resolve("app/build/tmp/kotlin-classes/debugAndroidTest/com/example/dagger/kotlin/TestClass.class")
465+
assertTrue(compilerClassFile.exists(),"File does not exist:${compilerClassFile.absolutePath}")
466+
checkBytecodeContains(compilerClassFile,"public final bar${'$'}app_debug()V")
467+
}
468+
}
469+
}
470+
442471
privatefunsetupDataBinding(project:Project) {
443472
project.setupWorkingDir()
444473

‎libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ class NewMultiplatformIT : BaseGradleIT() {
17811781
"Hello.internalFun\$new_mpp_associate_compilations",
17821782
"HelloTest.internalTestFun\$new_mpp_associate_compilations"
17831783
)
1784-
assertFileExists("build/classes/kotlin/jvm/integrationTest/META-INF/new-mpp-associate-compilations_integrationTest.kotlin_module")
1784+
assertFileExists("build/classes/kotlin/jvm/integrationTest/META-INF/new-mpp-associate-compilations.kotlin_module")
17851785

17861786
// JS:
17871787
assertFileExists(

‎libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kapt2/android-dagger/app/build.gradle‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ dependencies {
3535

3636
implementation'com.google.dagger:dagger:2.9'
3737
kapt'com.google.dagger:dagger-compiler:2.9'
38+
kapt'javax.annotation:javax.annotation-api:1.3.2'
39+
kaptAndroidTest'com.google.dagger:dagger-compiler:2.9'
40+
kaptAndroidTest'javax.annotation:javax.annotation-api:1.3.2'
3841
compileOnly'org.glassfish:javax.annotation:10.0-b28'
3942
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
packagecom.example.dagger.kotlin
7+
8+
classTestClass {
9+
internalfunbar() {
10+
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
packagecom.example.dagger.kotlin
7+
8+
importcom.example.dagger.kotlin.ui.HomeActivity
9+
importdagger.Component
10+
importjavax.inject.Singleton
11+
12+
@Singleton
13+
@Component
14+
interfaceTestComponent {
15+
funinject(application:BaseApplication)
16+
}

‎libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentsContributor.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,9 @@ internal open class KotlinJvmCompilerArgumentsContributor(
9898
args.destinationAsFile= destinationDir
9999

100100
compilerOptions.fillCompilerArguments(args)
101+
// Restoring moduleName overwritten by fillCompilerArguments default value
102+
if (args.moduleName==null) {
103+
args.moduleName= moduleName
104+
}
101105
}
102106
}

‎libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptGenerateStubsTask.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,9 @@ abstract class KaptGenerateStubsTask @Inject constructor(
123123
args.verbose= verbose.get()
124124
args.classpathAsList=this.libraries.filter { it.exists() }.toList()
125125
args.destinationAsFile=this.destinationDirectory.get().asFile
126+
// Setting moduleName from task input if it has default complierOptions value
127+
if (args.moduleName==null) {
128+
args.moduleName= moduleName.get()
129+
}
126130
}
127131
}

‎libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ abstract class KotlinCompile @Inject constructor(
538538
UsesKotlinJavaToolchain {
539539

540540
init {
541-
compilerOptions.moduleName.convention(moduleName)
542541
compilerOptions.verbose.convention(logger.isDebugEnabled)
543542
}
544543

‎libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinCompileConfig.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal open class BaseKotlinCompileConfig<TASK : KotlinCompile> : AbstractKotl
7575
task.associatedJavaCompileTaskTargetCompatibility.value(javaTaskProvider.map { it.targetCompatibility })
7676
task.associatedJavaCompileTaskName.value(javaTaskProvider.map { it.name })
7777
task.ownModuleName.value(
78-
(compilation.compilerOptions.optionsasKotlinJvmCompilerOptions).moduleName.convention(compilation.ownModuleName)
78+
(compilation.compilerOptions.optionsasKotlinJvmCompilerOptions).moduleName.orElse(compilation.ownModuleName)
7979
)
8080
}
8181
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp