Fix inter-project IC for kaptGenerateStubs task with AGP

In Android projects we need to detect modules by inspecting jar files
in order to find build history files.
However `useModuleDetection` property was not set up correctly for
KaptGenerateStubsTask.

    #KT-29761 Fixed
This commit is contained in:
Alexey Tsvetkov
2019-01-29 06:11:17 +03:00
parent 1bfd6705cc
commit efe93176ab
19 changed files with 192 additions and 1 deletions
@@ -1,6 +1,7 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.jetbrains.kotlin.gradle.util.checkedReplace
import org.jetbrains.kotlin.gradle.util.getFileByName
import org.jetbrains.kotlin.gradle.util.modify
import org.jetbrains.kotlin.test.KotlinTestUtils
@@ -127,6 +128,33 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
}
}
@Test
fun testInterProjectIC() = with(Project("android-inter-project-ic", directoryPrefix = "kapt2")) {
build("assembleDebug") {
assertSuccessful()
assertKaptSuccessful()
}
fun modifyAndCheck(utilFileName: String, useUtilFileName: String) {
val utilKt = projectDir.getFileByName(utilFileName)
utilKt.modify {
it.checkedReplace("Int", "Number")
}
build("assembleDebug") {
assertSuccessful()
val affectedFile = projectDir.getFileByName(useUtilFileName)
assertCompiledKotlinSources(
relativize(affectedFile),
tasks = listOf("app:kaptGenerateStubsDebugKotlin", "app:compileDebugKotlin")
)
}
}
modifyAndCheck("libAndroidUtil.kt", "useLibAndroidUtil.kt")
modifyAndCheck("libJvmUtil.kt", "useLibJvmUtil.kt")
}
@Test
fun testICWithAnonymousClasses() {
val project = Project("icAnonymousTypes", directoryPrefix = "kapt2")
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "org.example.inter.project.ic"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile project(':lib-android')
compile project(':lib-jvm')
compile "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
kapt "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.inter.project.ic">
<application android:name=".App">
</application>
</manifest>
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic
import android.app.Application
@example.ExampleAnnotation
class App : Application() {
private fun generated() = AppGenerated()
}
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic
fun appDummy() {}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic
import org.example.inter.project.ic.androidLib.*
fun useLibAndroidUtil() = libAndroidUtil()
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic
import org.example.inter.project.ic.jvmLib.*
fun useLibJvmUtil() = libJvmUtil()
@@ -0,0 +1,19 @@
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$android_tools_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
subprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
jcenter()
}
}
@@ -0,0 +1,18 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.example.inter.project.ic.androidLib"/>
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic.androidLib
fun libAndroidDummy() {}
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic.androidLib
fun libAndroidUtil(): Int = 0
@@ -0,0 +1,5 @@
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic.jvmLib
fun libJvmDummy() {}
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.example.inter.project.ic.jvmLib
fun libJvmUtil(): Int = 0
@@ -59,6 +59,13 @@ open class KaptGenerateStubsTask : KotlinCompile() {
internal val kotlinTaskPluginClasspath
get() = kotlinCompileTask.pluginClasspath
@get:Input
override var useModuleDetection: Boolean
get() = kotlinCompileTask.useModuleDetection
set(_) {
error("KaptGenerateStubsTask.useModuleDetection setter should not be called!")
}
override fun source(vararg sources: Any?): SourceTask? {
return super.source(sourceRootsContainer.add(sources))
}
@@ -141,7 +141,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
get() = File(taskBuildDirectory, "build-history.bin")
@get:Input
internal var useModuleDetection: Boolean = false
internal open var useModuleDetection: Boolean = false
@get:Internal
protected val multiModuleICSettings: MultiModuleICSettings