[KAPT] Skip kapt tasks if no annotations processors are provided (#4190)
So we don't do any preparation, don't spin up compiler. And user will see SKIPPED in task execution
This commit is contained in:
+13
@@ -525,6 +525,13 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
registerSubpluginOptions(kaptTaskProvider, subpluginOptions)
|
||||
}
|
||||
|
||||
kaptTaskProvider.configure { task ->
|
||||
task.onlyIf {
|
||||
it as KaptTask
|
||||
it.includeCompileClasspath || !it.kaptClasspath.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
return kaptTaskProvider
|
||||
}
|
||||
|
||||
@@ -568,6 +575,12 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
kaptTask.kaptClasspathConfigurations = kaptClasspathConfigurations
|
||||
|
||||
PropertiesProvider(project).mapKotlinTaskProperties(kaptTask)
|
||||
|
||||
if (!includeCompileClasspath) {
|
||||
kaptTask.onlyIf {
|
||||
!(it as KaptGenerateStubsTask).kaptClasspath.isEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.whenEvaluated {
|
||||
|
||||
+4
-2
@@ -119,8 +119,10 @@ abstract class KaptWithoutKotlincTask @Inject constructor(private val workerExec
|
||||
)
|
||||
|
||||
// Skip annotation processing if no annotation processors were provided.
|
||||
if (annotationProcessorFqNames.isEmpty() && kaptClasspath.isEmpty())
|
||||
if (annotationProcessorFqNames.isEmpty() && kaptClasspath.isEmpty()) {
|
||||
logger.info("No annotation processors provided. Skip KAPT processing.")
|
||||
return
|
||||
}
|
||||
|
||||
val kaptClasspath = kaptJars + kotlinStdlibClasspath
|
||||
|
||||
@@ -301,4 +303,4 @@ internal data class KaptOptionsForWorker(
|
||||
val javacOptions: Map<String, String>,
|
||||
|
||||
val flags: Set<String>
|
||||
) : Serializable
|
||||
) : Serializable
|
||||
|
||||
@@ -209,6 +209,7 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
||||
if (processingClasspath.isEmpty()) {
|
||||
// Skip annotation processing if no annotation processors were provided
|
||||
if (mode != AptMode.WITH_COMPILATION) {
|
||||
logger.info("No annotation processors provided. Skip KAPT processing.")
|
||||
abortAnalysis()
|
||||
}
|
||||
return false
|
||||
@@ -274,4 +275,4 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
||||
return AnalysisResult.success(bindingTrace.bindingContext, module, shouldGenerateCode = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user