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