@@ -18,6 +18,7 @@ package com.google.devtools.ksp.gradle
18
18
19
19
import com.google.devtools.ksp.KspExperimental
20
20
import com.google.devtools.ksp.gradle.model.builder.KspModelBuilder
21
+ import com.google.devtools.ksp.gradle.AndroidPluginIntegration.useLegacyVariantApi
21
22
import org.gradle.api.Action
22
23
import org.gradle.api.Project
23
24
import org.gradle.api.Task
@@ -253,17 +254,25 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
253
254
val kotlinCompileProvider: TaskProvider <AbstractKotlinCompileTool <* >> =
254
255
project.locateTask(kotlinCompilation.compileKotlinTaskName) ? : return project.provider { emptyList() }
255
256
val kspExtension = project.extensions.getByType(KspExtension ::class .java)
256
- val kspConfigurations = kspConfigurations.find(kotlinCompilation)
257
- val nonEmptyKspConfigurations = kspConfigurations.filter { it.allDependencies.isNotEmpty() }
258
- if (nonEmptyKspConfigurations.isEmpty()) {
259
- return project.provider { emptyList() }
260
- }
261
257
if (kotlinCompileProvider.name == " compileKotlinMetadata" ) {
262
258
return project.provider { emptyList() }
263
259
}
264
260
if ((kotlinCompilation as ? KotlinSharedNativeCompilation )?.platformType == KotlinPlatformType .common) {
265
261
return project.provider { emptyList() }
266
262
}
263
+ assert (kotlinCompileProvider.name.startsWith(" compile" ))
264
+ val kspTaskName = kotlinCompileProvider.name.replaceFirst(" compile" , " ksp" )
265
+ val processorClasspath =
266
+ project.configurations.maybeCreate(" ${kspTaskName} ProcessorClasspath" ).markResolvable()
267
+ if (kotlinCompilation.platformType != KotlinPlatformType .androidJvm || useLegacyVariantApi) {
268
+ val nonEmptyKspConfigurations =
269
+ kspConfigurations.find(kotlinCompilation)
270
+ .filter { it.allDependencies.isNotEmpty() }
271
+ if (nonEmptyKspConfigurations.isEmpty()) {
272
+ return project.provider { emptyList() }
273
+ }
274
+ processorClasspath.extendsFrom(* nonEmptyKspConfigurations.toTypedArray())
275
+ }
267
276
268
277
val target = kotlinCompilation.target.name
269
278
val sourceSetName = kotlinCompilation.defaultSourceSet.name
@@ -297,12 +306,6 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
297
306
" $KSP_GROUP_ID :$KSP_COMPILER_PLUGIN_ID_NON_EMBEDDABLE :$KSP_VERSION "
298
307
)
299
308
300
- assert (kotlinCompileProvider.name.startsWith(" compile" ))
301
- val kspTaskName = kotlinCompileProvider.name.replaceFirst(" compile" , " ksp" )
302
-
303
- val processorClasspath = project.configurations.maybeCreate(" ${kspTaskName} ProcessorClasspath" )
304
- .extendsFrom(* nonEmptyKspConfigurations.toTypedArray()).markResolvable()
305
-
306
309
val kspCachesDir = getKspCachesDir(project, sourceSetName, target)
307
310
fun configureAsKspTask (kspTask : KspTask , isIncremental : Boolean ) {
308
311
// depends on the processor; if the processor changes, it needs to be reprocessed.
0 commit comments