[Gradle] Suppress Android deprecations in Kapt3KotlinGradleSubplugin.kt
^KT-56904 In Progress
This commit is contained in:
committed by
Space Team
parent
7b409d0505
commit
56c7309fad
+19
-13
@@ -6,9 +6,6 @@
|
||||
package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
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.artifacts.Configuration
|
||||
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.tasks.*
|
||||
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.findResolvable
|
||||
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) {
|
||||
for (provider in androidVariantData.sourceSets) {
|
||||
handleSourceSet((provider as AndroidSourceSet).name)
|
||||
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
|
||||
handleSourceSet((provider as DeprecatedAndroidSourceSet).name)
|
||||
}
|
||||
androidVariantData.name
|
||||
} 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
|
||||
// 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
|
||||
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,
|
||||
project: Project,
|
||||
kotlinSourcesOutputDir: Iterable<File>,
|
||||
variantData: BaseVariant?,
|
||||
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION") variantData: DeprecatedAndroidBaseVariant?,
|
||||
androidExtension: BaseExtension?
|
||||
): Provider<List<SubpluginOption>> {
|
||||
return project.provider {
|
||||
@@ -598,15 +599,17 @@ private fun encodeList(options: Map<String, String>): String {
|
||||
// Gradle plugin on the project's plugin classpath
|
||||
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:
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun androidVariantData(context: Kapt3GradleSubplugin.Kapt3SubpluginContext): BaseVariant? = context.variantData as? BaseVariant
|
||||
@Suppress("NOTHING_TO_INLINE", "TYPEALIAS_EXPANSION_DEPRECATION")
|
||||
inline fun androidVariantData(
|
||||
context: Kapt3GradleSubplugin.Kapt3SubpluginContext
|
||||
): DeprecatedAndroidBaseVariant? = context.variantData as? DeprecatedAndroidBaseVariant
|
||||
|
||||
@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:
|
||||
inline fun registerGeneratedJavaSourceForAndroid(
|
||||
kapt3SubpluginContext: Kapt3GradleSubplugin.Kapt3SubpluginContext,
|
||||
project: Project,
|
||||
variantData: BaseVariant,
|
||||
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION") variantData: DeprecatedAndroidBaseVariant,
|
||||
kaptTask: TaskProvider<out 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
|
||||
|
||||
private val BaseVariant.annotationProcessorOptionProviders: List<CommandLineArgumentProvider>
|
||||
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
|
||||
private val DeprecatedAndroidBaseVariant.annotationProcessorOptionProviders: List<CommandLineArgumentProvider>
|
||||
get() = javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders
|
||||
|
||||
//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
|
||||
.find { it.name == "getDataBindingDependencyArtifacts" }
|
||||
?.also { it.isAccessible = true }
|
||||
|
||||
+12
@@ -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
|
||||
Reference in New Issue
Block a user