Store module info under own module name for incremental compilation
#KT-51463 Fixed
This commit is contained in:
+87
-53
@@ -666,6 +666,38 @@ open class KotlinAndroid70GradleIT : KotlinAndroid36GradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAndroidWithKaptIncremental() {
|
||||
val project = Project("AndroidIncrementalMultiModule")
|
||||
val options = defaultBuildOptions().copy(incremental = true)
|
||||
project.setupWorkingDir().also {
|
||||
project.gradleBuildScript("app").modify {
|
||||
"""
|
||||
apply plugin: 'org.jetbrains.kotlin.kapt'
|
||||
$it
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
project.build(":app:testDebugUnitTest", options = options) {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
project.projectDir
|
||||
.resolve("app/src/main/kotlin/com/example/KotlinActivity.kt")
|
||||
.appendText(
|
||||
"""
|
||||
{
|
||||
private val x = 1
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
project.build(":app:testDebugUnitTest", options = options) {
|
||||
assertSuccessful()
|
||||
assertNotContains("Non-incremental compilation will be performed")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNamespaceDSLInsteadOfPackageAttributeInManifest() {
|
||||
val project = Project("AndroidExtensionsProjectAGP7")
|
||||
@@ -761,38 +793,39 @@ abstract class KotlinAndroid3GradleIT : AbstractKotlinAndroidGradleTests() {
|
||||
|
||||
gradleBuildScript("Lib").writeText(
|
||||
"""
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
google()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:${'$'}android_tools_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${'$'}kotlin_version"
|
||||
}
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
google()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform'
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:${'$'}android_tools_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${'$'}kotlin_version"
|
||||
}
|
||||
|
||||
class MyAction implements kotlin.jvm.functions.Function1<Project, Void> {
|
||||
Void invoke(Project p) {
|
||||
println("compilations: " + p.kotlin.targets.getByName("android").compilations.names)
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform'
|
||||
}
|
||||
|
||||
class MyAction implements kotlin.jvm.functions.Function1<Project, Void> {
|
||||
Void invoke (Project p) {
|
||||
println("compilations: " + p.kotlin.targets.getByName("android").compilations.names)
|
||||
}
|
||||
|
||||
org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginKt.whenEvaluated(project, new MyAction())
|
||||
|
||||
apply plugin: "android-library"
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
}
|
||||
|
||||
kotlin { android("android") { } }
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginKt.whenEvaluated(project, new MyAction ())
|
||||
|
||||
apply plugin : "android-library"
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
}
|
||||
|
||||
kotlin { android("android") { } }
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build("help") {
|
||||
assertSuccessful()
|
||||
@@ -885,10 +918,10 @@ abstract class AbstractKotlinAndroidGradleTests : BaseGradleIT() {
|
||||
val getSomethingKt = project.projectDir.walk().filter { it.isFile && it.name.endsWith("getSomething.kt") }.first()
|
||||
getSomethingKt.writeText(
|
||||
"""
|
||||
package com.example
|
||||
package com.example
|
||||
|
||||
fun getSomething() = 10
|
||||
"""
|
||||
fun getSomething() = 10
|
||||
"""
|
||||
)
|
||||
|
||||
project.build("assembleDebug", options = options) {
|
||||
@@ -968,11 +1001,12 @@ fun getSomething() = 10
|
||||
|
||||
project.projectDir.resolve("app/build.gradle").appendText(
|
||||
"""
|
||||
|
|
||||
|androidExtensions {
|
||||
|
|
||||
|androidExtensions {
|
||||
| experimental = true
|
||||
|}
|
||||
""".trimMargin()
|
||||
|
|
||||
}
|
||||
""".trimMargin()
|
||||
)
|
||||
|
||||
project.build("assembleDebug") {
|
||||
@@ -1129,27 +1163,27 @@ fun getSomething() = 10
|
||||
|
||||
gradleBuildScript().modify {
|
||||
"""
|
||||
plugins {
|
||||
id("com.android.lint")
|
||||
}
|
||||
|
||||
""".trimIndent() + it
|
||||
plugins {
|
||||
id("com.android.lint")
|
||||
}
|
||||
|
||||
""".trimIndent() + it
|
||||
}
|
||||
|
||||
gradleBuildScript("Lib").appendText(
|
||||
"\n" + """
|
||||
android {
|
||||
lintOptions.checkDependencies = true
|
||||
}
|
||||
dependencies {
|
||||
implementation(project(":java-lib"))
|
||||
}
|
||||
android {
|
||||
lintOptions.checkDependencies = true
|
||||
}
|
||||
dependencies {
|
||||
implementation(project(":java-lib"))
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
gradleSettingsScript().appendText(
|
||||
"\n" + """
|
||||
include("java-lib")
|
||||
include("java-lib")
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -1157,11 +1191,11 @@ fun getSomething() = 10
|
||||
ensureParentDirsCreated()
|
||||
writeText(
|
||||
"""
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("com.android.lint")
|
||||
}
|
||||
""".trimIndent()
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("com.android.lint")
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -41,6 +41,7 @@ class KotlinJvmApiTest : KGPBaseTest() {
|
||||
it.source("src/main")
|
||||
it.multiPlatformEnabled.set(false)
|
||||
it.moduleName.set("main")
|
||||
it.ownModuleName.set("main")
|
||||
it.sourceSetName.set("main")
|
||||
it.useModuleDetection.set(false)
|
||||
it.destinationDirectory.fileValue(new File(project.buildDir, "fooOutput"))
|
||||
@@ -94,6 +95,7 @@ class KotlinJvmApiTest : KGPBaseTest() {
|
||||
it.source("src/main")
|
||||
it.multiPlatformEnabled.set(false)
|
||||
it.moduleName.set("main")
|
||||
it.ownModuleName.set("main")
|
||||
it.sourceSetName.set("main")
|
||||
it.useModuleDetection.set(false)
|
||||
it.destinationDirectory.fileValue(new File(project.buildDir, "fooOutput"))
|
||||
|
||||
+1
@@ -21,4 +21,5 @@ dependencies {
|
||||
implementation project(":libJvmClassesOnly")
|
||||
implementation project(":libAndroid")
|
||||
implementation project(":libAndroidClassesOnly")
|
||||
testImplementation "junit:junit:4.13.2"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.example
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.Assert.*
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class UnitTest {
|
||||
@Test
|
||||
fun isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -295,7 +295,7 @@ internal open class GradleCompilerRunner(
|
||||
if (task is AbstractKotlinCompile<*>) {
|
||||
val module = IncrementalModuleEntry(
|
||||
project.path,
|
||||
task.moduleName.get(),
|
||||
task.ownModuleName.get(),
|
||||
project.buildDir,
|
||||
task.buildHistoryFile.get().asFile,
|
||||
task.abiSnapshotFile.get().asFile
|
||||
@@ -327,7 +327,7 @@ internal open class GradleCompilerRunner(
|
||||
val kotlinTask = mainCompilation.compileKotlinTask as? AbstractKotlinCompile<*> ?: continue
|
||||
val module = IncrementalModuleEntry(
|
||||
project.path,
|
||||
kotlinTask.moduleName.get(),
|
||||
kotlinTask.ownModuleName.get(),
|
||||
project.buildDir,
|
||||
kotlinTask.buildHistoryFile.get().asFile,
|
||||
kotlinTask.abiSnapshotFile.get().asFile
|
||||
|
||||
+3
@@ -274,6 +274,9 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
|
||||
@get:Internal
|
||||
val startParameters = BuildMetricsReporterService.getStartParameters(project)
|
||||
|
||||
@get:Input
|
||||
abstract val ownModuleName: Property<String>
|
||||
|
||||
@get:Internal
|
||||
internal abstract val buildMetricsReporterService: Property<BuildMetricsReporterService?>
|
||||
|
||||
|
||||
+1
@@ -94,6 +94,7 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
|
||||
)
|
||||
}
|
||||
task.moduleName.set(providers.provider { compilation.moduleName })
|
||||
task.ownModuleName.set(project.provider { compilation.ownModuleName })
|
||||
task.sourceSetName.value(providers.provider { compilation.compilationPurpose })
|
||||
task.multiPlatformEnabled.value(
|
||||
providers.provider {
|
||||
|
||||
+2
-2
@@ -76,9 +76,9 @@ internal open class BaseKotlinCompileConfig<TASK : KotlinCompile> : AbstractKotl
|
||||
task.associatedJavaCompileTaskSources.from(javaTaskProvider.map { it.source })
|
||||
task.associatedJavaCompileTaskName.value(javaTaskProvider.name)
|
||||
}
|
||||
task.moduleName.value(providers.provider {
|
||||
task.ownModuleName.value(providers.provider {
|
||||
(compilation.kotlinOptions as? KotlinJvmOptions)?.moduleName ?: task.parentKotlinOptions.orNull?.moduleName
|
||||
?: compilation.moduleName
|
||||
?: compilation.ownModuleName
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user