[Gradle] Suppress Android deprecations in Kapt3KotlinGradleSubplugin.kt

^KT-56904 In Progress
This commit is contained in:
Yahor Berdnikau
2023-12-09 22:12:26 +01:00
committed by Space Team
parent 7b409d0505
commit 56c7309fad
2 changed files with 31 additions and 13 deletions
@@ -6,9 +6,6 @@
package org.jetbrains.kotlin.gradle.internal package org.jetbrains.kotlin.gradle.internal
import com.android.build.gradle.BaseExtension import com.android.build.gradle.BaseExtension
import com.android.build.gradle.api.AndroidSourceSet
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.api.SourceKind
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.Dependency
@@ -32,6 +29,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaCompilation
import org.jetbrains.kotlin.gradle.tasks.* import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.configuration.* import org.jetbrains.kotlin.gradle.tasks.configuration.*
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.gradle.utils.createResolvable import org.jetbrains.kotlin.gradle.utils.createResolvable
import org.jetbrains.kotlin.gradle.utils.findResolvable import org.jetbrains.kotlin.gradle.utils.findResolvable
import org.jetbrains.kotlin.gradle.utils.whenEvaluated import org.jetbrains.kotlin.gradle.utils.whenEvaluated
@@ -263,11 +261,13 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
} }
} }
val androidVariantData: BaseVariant? = (kotlinCompilation as? KotlinJvmAndroidCompilation)?.androidVariant @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
val androidVariantData: DeprecatedAndroidBaseVariant? = (kotlinCompilation as? KotlinJvmAndroidCompilation)?.androidVariant
val sourceSetName = if (androidVariantData != null) { val sourceSetName = if (androidVariantData != null) {
for (provider in androidVariantData.sourceSets) { for (provider in androidVariantData.sourceSets) {
handleSourceSet((provider as AndroidSourceSet).name) @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
handleSourceSet((provider as DeprecatedAndroidSourceSet).name)
} }
androidVariantData.name androidVariantData.name
} else { } else {
@@ -303,7 +303,8 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
// Avoid circular dependency: the stubs task need the Java sources, but the Java sources generated by Kapt should be // Avoid circular dependency: the stubs task need the Java sources, but the Java sources generated by Kapt should be
// excluded, as the Kapt tasks depend on the stubs ones, and having them in the input would lead to a cycle // excluded, as the Kapt tasks depend on the stubs ones, and having them in the input would lead to a cycle
val kaptJavaOutput = kaptTaskProvider.get().destinationDir.get().asFile val kaptJavaOutput = kaptTaskProvider.get().destinationDir.get().asFile
androidVariantData.getSourceFolders(SourceKind.JAVA).filter { it.dir != kaptJavaOutput } @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
androidVariantData.getSourceFolders(DeprecatedAndroidSourceKind.JAVA).filter { it.dir != kaptJavaOutput }
} }
) )
} }
@@ -570,7 +571,7 @@ internal fun getNonAndroidDslApOptions(
kaptExtension: KaptExtension, kaptExtension: KaptExtension,
project: Project, project: Project,
kotlinSourcesOutputDir: Iterable<File>, kotlinSourcesOutputDir: Iterable<File>,
variantData: BaseVariant?, @Suppress("TYPEALIAS_EXPANSION_DEPRECATION") variantData: DeprecatedAndroidBaseVariant?,
androidExtension: BaseExtension? androidExtension: BaseExtension?
): Provider<List<SubpluginOption>> { ): Provider<List<SubpluginOption>> {
return project.provider { return project.provider {
@@ -598,15 +599,17 @@ private fun encodeList(options: Map<String, String>): String {
// Gradle plugin on the project's plugin classpath // Gradle plugin on the project's plugin classpath
private object KaptWithAndroid { private object KaptWithAndroid {
// Avoid loading the BaseVariant type at call sites and instead lazily load it when evaluation reaches it in the body using inline: // Avoid loading the BaseVariant type at call sites and instead lazily load it when evaluation reaches it in the body using inline:
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE", "TYPEALIAS_EXPANSION_DEPRECATION")
inline fun androidVariantData(context: Kapt3GradleSubplugin.Kapt3SubpluginContext): BaseVariant? = context.variantData as? BaseVariant inline fun androidVariantData(
context: Kapt3GradleSubplugin.Kapt3SubpluginContext
): DeprecatedAndroidBaseVariant? = context.variantData as? DeprecatedAndroidBaseVariant
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
// Avoid loading the BaseVariant type at call sites and instead lazily load it when evaluation reaches it in the body using inline: // Avoid loading the BaseVariant type at call sites and instead lazily load it when evaluation reaches it in the body using inline:
inline fun registerGeneratedJavaSourceForAndroid( inline fun registerGeneratedJavaSourceForAndroid(
kapt3SubpluginContext: Kapt3GradleSubplugin.Kapt3SubpluginContext, kapt3SubpluginContext: Kapt3GradleSubplugin.Kapt3SubpluginContext,
project: Project, project: Project,
variantData: BaseVariant, @Suppress("TYPEALIAS_EXPANSION_DEPRECATION") variantData: DeprecatedAndroidBaseVariant,
kaptTask: TaskProvider<out KaptTask> kaptTask: TaskProvider<out KaptTask>
) { ) {
val kaptSourceOutput = project.fileTree(kapt3SubpluginContext.sourcesOutputDir).builtBy(kaptTask) val kaptSourceOutput = project.fileTree(kapt3SubpluginContext.sourcesOutputDir).builtBy(kaptTask)
@@ -677,14 +680,17 @@ internal fun checkAndroidAnnotationProcessorDependencyUsage(project: Project) {
} }
} }
private val BaseVariant.annotationProcessorOptions: Map<String, String>? @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
private val DeprecatedAndroidBaseVariant.annotationProcessorOptions: Map<String, String>?
get() = javaCompileOptions.annotationProcessorOptions.arguments get() = javaCompileOptions.annotationProcessorOptions.arguments
private val BaseVariant.annotationProcessorOptionProviders: List<CommandLineArgumentProvider> @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
private val DeprecatedAndroidBaseVariant.annotationProcessorOptionProviders: List<CommandLineArgumentProvider>
get() = javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders get() = javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders
//TODO once the Android plugin reaches its 3.0.0 release, consider compiling against it (remove the reflective call) //TODO once the Android plugin reaches its 3.0.0 release, consider compiling against it (remove the reflective call)
private val BaseVariant.dataBindingDependencyArtifactsIfSupported: FileCollection? @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
private val DeprecatedAndroidBaseVariant.dataBindingDependencyArtifactsIfSupported: FileCollection?
get() = this::class.java.methods get() = this::class.java.methods
.find { it.name == "getDataBindingDependencyArtifacts" } .find { it.name == "getDataBindingDependencyArtifacts" }
?.also { it.isAccessible = true } ?.also { it.isAccessible = true }
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2023 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.
*/
@file:Suppress("DEPRECATION")
package org.jetbrains.kotlin.gradle.utils
internal typealias DeprecatedAndroidSourceSet = com.android.build.gradle.api.AndroidSourceSet
internal typealias DeprecatedAndroidBaseVariant = com.android.build.gradle.api.BaseVariant
internal typealias DeprecatedAndroidSourceKind = com.android.build.gradle.api.SourceKind