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:
+28
@@ -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")
|
||||
|
||||
+28
@@ -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"
|
||||
}
|
||||
+8
@@ -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>
|
||||
+13
@@ -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()
|
||||
}
|
||||
+8
@@ -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() {}
|
||||
+10
@@ -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()
|
||||
+10
@@ -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()
|
||||
+19
@@ -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()
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
kapt.verbose=true
|
||||
+18
@@ -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"
|
||||
}
|
||||
+3
@@ -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"/>
|
||||
+8
@@ -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() {}
|
||||
+8
@@ -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
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
+8
@@ -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() {}
|
||||
+8
@@ -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
|
||||
+1
@@ -0,0 +1 @@
|
||||
include ':app', ':lib-android', ':lib-jvm'
|
||||
+7
@@ -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))
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user