Subplugin options refactoring & Gradle input improvements
Introduce FilesSubpluginOption Special kind of SubpluginOption that holds a list of files together with the kind of these files with respect to the task. Add a logic for handling such options and converting them into task inputs. Refactor CompilerPluginOptions: make it store subplugin options to be able to add options from KotlinCompile to the kapt tasks. Introduce WrapperSubpluginOption for encoded and complex options. Remove pluginOptions from the Gradle inputs built from the compiler args. Do not cache Kotlin compilation with kapt1 enabled: since we are going to drop kapt1 it anyway, there's no point in implementing proper cache for it, so just disable the caching of the task in case kapt1 is used.
This commit is contained in:
+17
-1
@@ -19,8 +19,24 @@ package org.jetbrains.kotlin.gradle.plugin
|
|||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.tasks.SourceSet
|
import org.gradle.api.tasks.SourceSet
|
||||||
import org.gradle.api.tasks.compile.AbstractCompile
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class SubpluginOption(val key: String, val value: String)
|
open class SubpluginOption(val key: String, open val value: String)
|
||||||
|
|
||||||
|
class FilesSubpluginOption(
|
||||||
|
key: String,
|
||||||
|
val kind: FileOptionKind,
|
||||||
|
val files: List<File>,
|
||||||
|
value: String = files.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||||
|
: SubpluginOption(key, value)
|
||||||
|
|
||||||
|
class WrapperSubpluginOption(
|
||||||
|
key: String,
|
||||||
|
value: String,
|
||||||
|
val originalOptions: List<SubpluginOption>)
|
||||||
|
: SubpluginOption(key, value)
|
||||||
|
|
||||||
|
enum class FileOptionKind { INPUT_FILES, CLASSPATH_INPUT, OUTPUT_FILES, OUTPUT_DIRS, INTERNAL }
|
||||||
|
|
||||||
interface KotlinGradleSubplugin<in KotlinCompile : AbstractCompile> {
|
interface KotlinGradleSubplugin<in KotlinCompile : AbstractCompile> {
|
||||||
fun isApplicable(project: Project, task: AbstractCompile): Boolean
|
fun isApplicable(project: Project, task: AbstractCompile): Boolean
|
||||||
|
|||||||
+13
-4
@@ -116,8 +116,13 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
pluginOptions += SubpluginOption("package", applicationPackage)
|
pluginOptions += SubpluginOption("package", applicationPackage)
|
||||||
|
|
||||||
fun addVariant(sourceSet: AndroidSourceSet) {
|
fun addVariant(sourceSet: AndroidSourceSet) {
|
||||||
pluginOptions += SubpluginOption("variant", sourceSet.name + ';' +
|
val optionValue = sourceSet.name + ';' +
|
||||||
sourceSet.res.srcDirs.joinToString(";") { it.absolutePath })
|
sourceSet.res.srcDirs.joinToString(";") { it.absolutePath }
|
||||||
|
pluginOptions += WrapperSubpluginOption("variant", optionValue, listOf(
|
||||||
|
SubpluginOption("sourceSetName", sourceSet.name),
|
||||||
|
//use the INTERNAL option kind since the resources are tracked as sources (see below)
|
||||||
|
FilesSubpluginOption("resDirs", FileOptionKind.INTERNAL, sourceSet.res.srcDirs.toList())
|
||||||
|
))
|
||||||
kotlinCompile.source(project.files(getLayoutDirectories(sourceSet.res.srcDirs)))
|
kotlinCompile.source(project.files(getLayoutDirectories(sourceSet.res.srcDirs)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,11 +165,15 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
pluginOptions += SubpluginOption("package", getApplicationPackage(project, mainSourceSet))
|
pluginOptions += SubpluginOption("package", getApplicationPackage(project, mainSourceSet))
|
||||||
|
|
||||||
fun addVariant(name: String, resDirectories: List<File>) {
|
fun addVariant(name: String, resDirectories: List<File>) {
|
||||||
pluginOptions += SubpluginOption("variant", buildString {
|
val optionValue = buildString {
|
||||||
append(name)
|
append(name)
|
||||||
append(';')
|
append(';')
|
||||||
resDirectories.joinTo(this, separator = ";") { it.canonicalPath }
|
resDirectories.joinTo(this, separator = ";") { it.canonicalPath }
|
||||||
})
|
}
|
||||||
|
pluginOptions += WrapperSubpluginOption("variant", optionValue, listOf(
|
||||||
|
SubpluginOption("variantName", name),
|
||||||
|
// use INTERNAL option kind since the resources are tracked as sources (see below)
|
||||||
|
FilesSubpluginOption("resDirs", FileOptionKind.INTERNAL, resDirectories)))
|
||||||
|
|
||||||
kotlinCompile.source(project.files(getLayoutDirectories(resDirectories)))
|
kotlinCompile.source(project.files(getLayoutDirectories(resDirectories)))
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
import org.jetbrains.kotlin.gradle.tasks.kapt.generateAnnotationProcessorWrapper
|
import org.jetbrains.kotlin.gradle.tasks.kapt.generateAnnotationProcessorWrapper
|
||||||
import org.jetbrains.kotlin.gradle.tasks.kapt.generateKotlinAptAnnotation
|
import org.jetbrains.kotlin.gradle.tasks.kapt.generateKotlinAptAnnotation
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.shouldEnableGradleCache
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
@@ -78,6 +79,11 @@ internal fun Project.initKapt(
|
|||||||
// javaTask.doLast {
|
// javaTask.doLast {
|
||||||
// moveGeneratedJavaFilesToCorrespondingDirectories(kaptManager.aptOutputDir)
|
// moveGeneratedJavaFilesToCorrespondingDirectories(kaptManager.aptOutputDir)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if (shouldEnableGradleCache()) {
|
||||||
|
// Since Kapt1 is about to be dropped, disable the cache for it:
|
||||||
|
kotlinAfterJavaTask.outputs.doNotCacheIf("Caching is not supported with deprecated Kapt1") { true }
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
kotlinAfterJavaTask = null
|
kotlinAfterJavaTask = null
|
||||||
kotlinTask.logger.kotlinDebug("kapt: Class file stubs are not used")
|
kotlinTask.logger.kotlinDebug("kapt: Class file stubs are not used")
|
||||||
@@ -103,6 +109,12 @@ internal fun Project.initKapt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlinTask.kaptOptions.annotationsFile = kaptManager.getAnnotationFile()
|
kotlinTask.kaptOptions.annotationsFile = kaptManager.getAnnotationFile()
|
||||||
|
|
||||||
|
if (shouldEnableGradleCache()) {
|
||||||
|
// Since Kapt1 is about to be dropped, disable the cache for it:
|
||||||
|
kotlinTask.outputs.doNotCacheIf("Caching is not supported with deprecated Kapt1") { true }
|
||||||
|
}
|
||||||
|
|
||||||
return kotlinAfterJavaTask
|
return kotlinAfterJavaTask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-23
@@ -21,6 +21,7 @@ import com.android.build.gradle.api.AndroidSourceSet
|
|||||||
import com.android.builder.model.SourceProvider
|
import com.android.builder.model.SourceProvider
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.Dependency
|
import org.gradle.api.artifacts.Dependency
|
||||||
import org.gradle.api.tasks.SourceSet
|
import org.gradle.api.tasks.SourceSet
|
||||||
@@ -209,14 +210,14 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
pluginOptions += SubpluginOption("aptMode", aptMode)
|
pluginOptions += SubpluginOption("aptMode", aptMode)
|
||||||
disableAnnotationProcessingInJavaTask()
|
disableAnnotationProcessingInJavaTask()
|
||||||
|
|
||||||
kaptClasspath.forEach { pluginOptions += SubpluginOption("apclasspath", it.absolutePath) }
|
kaptClasspath.forEach { pluginOptions += FilesSubpluginOption("apclasspath", FileOptionKind.INTERNAL, listOf(it)) }
|
||||||
|
|
||||||
javaCompile.source(generatedFilesDir)
|
javaCompile.source(generatedFilesDir)
|
||||||
|
|
||||||
pluginOptions += SubpluginOption("sources", generatedFilesDir.canonicalPath)
|
pluginOptions += FilesSubpluginOption("sources", FileOptionKind.INTERNAL, listOf(generatedFilesDir))
|
||||||
pluginOptions += SubpluginOption("classes", getKaptGeneratedClassesDir(project, sourceSetName).canonicalPath)
|
pluginOptions += FilesSubpluginOption("classes", FileOptionKind.INTERNAL, listOf(getKaptGeneratedClassesDir(project, sourceSetName)))
|
||||||
|
|
||||||
pluginOptions += SubpluginOption("incrementalData", getKaptIncrementalDataDir().canonicalPath)
|
pluginOptions += FilesSubpluginOption("incrementalData", FileOptionKind.INTERNAL, listOf(getKaptIncrementalDataDir()))
|
||||||
|
|
||||||
val annotationProcessors = kaptExtension.processors
|
val annotationProcessors = kaptExtension.processors
|
||||||
if (annotationProcessors.isNotEmpty()) {
|
if (annotationProcessors.isNotEmpty()) {
|
||||||
@@ -231,13 +232,12 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
|
|
||||||
kotlinSourcesOutputDir.mkdirs()
|
kotlinSourcesOutputDir.mkdirs()
|
||||||
|
|
||||||
val apOptions = kaptExtension.getAdditionalArguments(
|
val apOptions =
|
||||||
project,
|
(kaptExtension.getAdditionalArguments(project, kaptVariantData?.variantData, androidPlugin) + androidOptions)
|
||||||
kaptVariantData?.variantData,
|
.map { SubpluginOption(it.key, it.value) } +
|
||||||
androidPlugin
|
FilesSubpluginOption("kapt.kotlin.generated", FileOptionKind.INTERNAL, listOf(kotlinSourcesOutputDir))
|
||||||
) + androidOptions + mapOf("kapt.kotlin.generated" to kotlinSourcesOutputDir.absolutePath)
|
|
||||||
|
|
||||||
pluginOptions += SubpluginOption("apoptions", encodeList(apOptions))
|
pluginOptions += WrapperSubpluginOption("apoptions", encodeList(apOptions.associate { it.key to it.value }), apOptions)
|
||||||
|
|
||||||
pluginOptions += SubpluginOption("javacArguments", encodeList(kaptExtension.getJavacOptions()))
|
pluginOptions += SubpluginOption("javacArguments", encodeList(kaptExtension.getJavacOptions()))
|
||||||
|
|
||||||
@@ -246,10 +246,20 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
return pluginOptions
|
return pluginOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Kapt3SubpluginContext.buildAndAddOptionsTo(container: CompilerPluginOptions, aptMode: String) {
|
private fun Kapt3SubpluginContext.buildAndAddOptionsTo(task: Task, container: CompilerPluginOptions, aptMode: String) {
|
||||||
val compilerPluginId = getCompilerPluginId()
|
val compilerPluginId = getCompilerPluginId()
|
||||||
for (option in wrapPluginOptions(buildOptions(aptMode), "configuration")) {
|
for (option in wrapPluginOptions(buildOptions(aptMode), "configuration")) {
|
||||||
container.addPluginArgument(compilerPluginId, option.key, option.value)
|
container.addPluginArgument(compilerPluginId, option)
|
||||||
|
task.registerSubpluginOptionAsInput(compilerPluginId, option)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also register all the subplugin options from the Kotlin task:
|
||||||
|
project.afterEvaluate {
|
||||||
|
kotlinCompile.pluginOptions.subpluginOptionsByPluginId.forEach { (pluginId, options) ->
|
||||||
|
options.forEach { option ->
|
||||||
|
task.registerSubpluginOptionAsInput("kotlinCompile.$pluginId", option)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +284,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
|
|
||||||
pluginOptions += SubpluginOption("useLightAnalysis", "${kaptExtension.useLightAnalysis}")
|
pluginOptions += SubpluginOption("useLightAnalysis", "${kaptExtension.useLightAnalysis}")
|
||||||
pluginOptions += SubpluginOption("correctErrorTypes", "${kaptExtension.correctErrorTypes}")
|
pluginOptions += SubpluginOption("correctErrorTypes", "${kaptExtension.correctErrorTypes}")
|
||||||
pluginOptions += SubpluginOption("stubs", getKaptStubsDir().canonicalPath)
|
pluginOptions += FilesSubpluginOption("stubs", FileOptionKind.INTERNAL, listOf(getKaptStubsDir()))
|
||||||
|
|
||||||
if (project.hasProperty(VERBOSE_OPTION_NAME) && project.property(VERBOSE_OPTION_NAME) == "true") {
|
if (project.hasProperty(VERBOSE_OPTION_NAME) && project.property(VERBOSE_OPTION_NAME) == "true") {
|
||||||
pluginOptions += SubpluginOption("verbose", "true")
|
pluginOptions += SubpluginOption("verbose", "true")
|
||||||
@@ -288,6 +298,14 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
|
|
||||||
kaptTask.useBuildCacheIfSupported()
|
kaptTask.useBuildCacheIfSupported()
|
||||||
|
|
||||||
|
if (shouldEnableGradleCache()) {
|
||||||
|
val reason = "Caching is disabled by default for kapt because of arbitrary behavior of external " +
|
||||||
|
"annotation processors. You can enable it by adding 'kapt.useBuildCache = true' to the build script."
|
||||||
|
kaptTask.outputs.doNotCacheIf(reason) { !kaptTask.useBuildCache }
|
||||||
|
}
|
||||||
|
|
||||||
|
kaptTask.useBuildCache = kaptExtension.useBuildCache
|
||||||
|
|
||||||
kaptTask.kotlinCompileTask = kotlinCompile
|
kaptTask.kotlinCompileTask = kotlinCompile
|
||||||
|
|
||||||
kaptClasspathArtifacts.forEach { kaptTask.pluginOptions.addClasspathEntry(it) }
|
kaptClasspathArtifacts.forEach { kaptTask.pluginOptions.addClasspathEntry(it) }
|
||||||
@@ -314,15 +332,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
|
|
||||||
kaptTask.kaptClasspath = kaptClasspath
|
kaptTask.kaptClasspath = kaptClasspath
|
||||||
|
|
||||||
kaptTask.useBuildCache = kaptExtension.useBuildCache
|
buildAndAddOptionsTo(kaptTask, kaptTask.pluginOptions, aptMode = "apt")
|
||||||
|
|
||||||
if (shouldEnableGradleCache()) {
|
|
||||||
val reason = "Caching is disabled by default for kapt because of arbitrary behavior of external " +
|
|
||||||
"annotation processors. You can enable it by adding 'kapt.useBuildCache = true' to the build script."
|
|
||||||
kaptTask.outputs.doNotCacheIf(reason) { !kaptTask.useBuildCache }
|
|
||||||
}
|
|
||||||
|
|
||||||
buildAndAddOptionsTo(kaptTask.pluginOptions, aptMode = "apt")
|
|
||||||
|
|
||||||
return kaptTask
|
return kaptTask
|
||||||
}
|
}
|
||||||
@@ -347,7 +357,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
mapKotlinTaskProperties(project, kaptTask)
|
mapKotlinTaskProperties(project, kaptTask)
|
||||||
|
|
||||||
kaptTask.kaptClasspath = kaptClasspath
|
kaptTask.kaptClasspath = kaptClasspath
|
||||||
buildAndAddOptionsTo(kaptTask.pluginOptions, aptMode = "stubs")
|
buildAndAddOptionsTo(kaptTask, kaptTask.pluginOptions, aptMode = "stubs")
|
||||||
|
|
||||||
return kaptTask
|
return kaptTask
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.internal
|
package org.jetbrains.kotlin.gradle.internal
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.WrapperSubpluginOption
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -42,6 +43,6 @@ fun encodePluginOptions(options: Map<String, List<String>>): String {
|
|||||||
fun wrapPluginOptions(options: List<SubpluginOption>, newOptionName: String): List<SubpluginOption> {
|
fun wrapPluginOptions(options: List<SubpluginOption>, newOptionName: String): List<SubpluginOption> {
|
||||||
val groupedOptions = options.groupBy { it.key }.mapValues { opt -> opt.value.map { it.value } }
|
val groupedOptions = options.groupBy { it.key }.mapValues { opt -> opt.value.map { it.value } }
|
||||||
val encodedOptions = encodePluginOptions(groupedOptions)
|
val encodedOptions = encodePluginOptions(groupedOptions)
|
||||||
val singleOption = SubpluginOption(newOptionName, encodedOptions)
|
val singleOption = WrapperSubpluginOption(newOptionName, encodedOptions, options)
|
||||||
return listOf(singleOption)
|
return listOf(singleOption)
|
||||||
}
|
}
|
||||||
+41
-4
@@ -20,9 +20,7 @@ import org.gradle.api.plugins.InvalidPluginException
|
|||||||
import org.gradle.api.plugins.JavaBasePlugin
|
import org.gradle.api.plugins.JavaBasePlugin
|
||||||
import org.gradle.api.plugins.JavaPlugin
|
import org.gradle.api.plugins.JavaPlugin
|
||||||
import org.gradle.api.plugins.JavaPluginConvention
|
import org.gradle.api.plugins.JavaPluginConvention
|
||||||
import org.gradle.api.tasks.Delete
|
import org.gradle.api.tasks.*
|
||||||
import org.gradle.api.tasks.SourceSet
|
|
||||||
import org.gradle.api.tasks.SourceSetOutput
|
|
||||||
import org.gradle.api.tasks.compile.AbstractCompile
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
import org.gradle.api.tasks.compile.JavaCompile
|
import org.gradle.api.tasks.compile.JavaCompile
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
@@ -822,7 +820,9 @@ internal class SubpluginEnvironment(
|
|||||||
subpluginClasspath.forEach { pluginOptions.addClasspathEntry(it) }
|
subpluginClasspath.forEach { pluginOptions.addClasspathEntry(it) }
|
||||||
|
|
||||||
for (option in subplugin.apply(project, kotlinTask, javaTask, variantData, androidProjectHandler, javaSourceSet)) {
|
for (option in subplugin.apply(project, kotlinTask, javaTask, variantData, androidProjectHandler, javaSourceSet)) {
|
||||||
pluginOptions.addPluginArgument(subplugin.getCompilerPluginId(), option.key, option.value)
|
val pluginId = subplugin.getCompilerPluginId()
|
||||||
|
pluginOptions.addPluginArgument(pluginId, option)
|
||||||
|
kotlinTask.registerSubpluginOptionAsInput(pluginId, option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -830,6 +830,43 @@ internal class SubpluginEnvironment(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val fileOptionsPathSensitivity = PathSensitivity.ABSOLUTE
|
||||||
|
|
||||||
|
internal fun Task.registerSubpluginOptionAsInput(subpluginId: String, option: SubpluginOption) {
|
||||||
|
when (option) {
|
||||||
|
is WrapperSubpluginOption -> {
|
||||||
|
val subpluginIdWithWrapperKey = "$subpluginId.${option.key}"
|
||||||
|
option.originalOptions.forEach { registerSubpluginOptionAsInput(subpluginIdWithWrapperKey, it) }
|
||||||
|
}
|
||||||
|
is FilesSubpluginOption -> {
|
||||||
|
when (option.kind) {
|
||||||
|
FileOptionKind.INTERNAL -> Unit
|
||||||
|
FileOptionKind.OUTPUT_FILES -> outputsCompatible.filesCompatible(*option.files.toTypedArray())
|
||||||
|
FileOptionKind.OUTPUT_DIRS -> option.files.forEach { outputsCompatible.dirCompatible(it) }
|
||||||
|
FileOptionKind.INPUT_FILES, FileOptionKind.CLASSPATH_INPUT -> {
|
||||||
|
if (!shouldEnableGradleCache()) {
|
||||||
|
// Normalization makes no sense when we don't mean to use the cache,
|
||||||
|
// and moreover, Gradle lacks some of the APIs in the earlier versions.
|
||||||
|
inputsCompatible.filesCompatible(option.files)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (option.kind == FileOptionKind.CLASSPATH_INPUT)
|
||||||
|
inputs.files(option.files).withNormalizer(ClasspathNormalizer::class.java)
|
||||||
|
else
|
||||||
|
inputs.files(option.files).withPathSensitivity(fileOptionsPathSensitivity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
// Since there might be multiple subplugin options with the same key,
|
||||||
|
// use the properties count to resolve duplication:
|
||||||
|
val propertyInputsCount = inputsCompatible.properties.size
|
||||||
|
inputsCompatible.propertyCompatible("$subpluginId." + option.key + ".$propertyInputsCount", option.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair<File, File> {
|
private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair<File, File> {
|
||||||
val aptOutputDir = File(buildDir, "generated/source/kapt")
|
val aptOutputDir = File(buildDir, "generated/source/kapt")
|
||||||
val aptOutputDirForVariant = File(aptOutputDir, sourceSetName)
|
val aptOutputDirForVariant = File(aptOutputDir, sourceSetName)
|
||||||
|
|||||||
+7
-2
@@ -16,12 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.tasks
|
package org.jetbrains.kotlin.gradle.tasks
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
internal class CompilerPluginOptions {
|
internal class CompilerPluginOptions {
|
||||||
private val mutableClasspath = arrayListOf<String>()
|
private val mutableClasspath = arrayListOf<String>()
|
||||||
private val mutableArguments = arrayListOf<String>()
|
private val mutableArguments = arrayListOf<String>()
|
||||||
|
|
||||||
|
internal val subpluginOptionsByPluginId =
|
||||||
|
mutableMapOf<String, MutableList<SubpluginOption>>()
|
||||||
|
|
||||||
val classpath: List<String>
|
val classpath: List<String>
|
||||||
get() = mutableClasspath
|
get() = mutableClasspath
|
||||||
|
|
||||||
@@ -38,7 +42,8 @@ internal class CompilerPluginOptions {
|
|||||||
mutableClasspath.remove(file.canonicalPath)
|
mutableClasspath.remove(file.canonicalPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addPluginArgument(pluginId: String, key: String, value: String) {
|
fun addPluginArgument(pluginId: String, option: SubpluginOption) {
|
||||||
mutableArguments.add("plugin:$pluginId:$key=$value")
|
mutableArguments.add("plugin:$pluginId:${option.key}=${option.value}")
|
||||||
|
subpluginOptionsByPluginId.getOrPut(pluginId) { mutableListOf() }.add(option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -38,8 +38,7 @@ import org.jetbrains.kotlin.compilerRunner.*
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.*
|
import org.jetbrains.kotlin.gradle.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.internal.CompilerArgumentAware
|
import org.jetbrains.kotlin.gradle.internal.CompilerArgumentAware
|
||||||
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.kotlinInfo
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.ParsedGradleVersion
|
import org.jetbrains.kotlin.gradle.utils.ParsedGradleVersion
|
||||||
import org.jetbrains.kotlin.incremental.*
|
import org.jetbrains.kotlin.incremental.*
|
||||||
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistry
|
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistry
|
||||||
@@ -413,15 +412,15 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
|||||||
kaptAnnotationsFileUpdater = AnnotationFileUpdaterImpl(kaptAnnotationsFile)
|
kaptAnnotationsFileUpdater = AnnotationFileUpdaterImpl(kaptAnnotationsFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
addPluginArgument(ANNOTATIONS_PLUGIN_NAME, "output", kaptAnnotationsFile.canonicalPath)
|
addPluginArgument(ANNOTATIONS_PLUGIN_NAME, FilesSubpluginOption("output", FileOptionKind.INTERNAL, listOf(kaptAnnotationsFile)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kaptOptions.generateStubs) {
|
if (kaptOptions.generateStubs) {
|
||||||
addPluginArgument(ANNOTATIONS_PLUGIN_NAME, "stubs", destinationDir.canonicalPath)
|
addPluginArgument(ANNOTATIONS_PLUGIN_NAME, FilesSubpluginOption("stubs", FileOptionKind.INTERNAL, listOf(destinationDir)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kaptOptions.supportInheritedAnnotations) {
|
if (kaptOptions.supportInheritedAnnotations) {
|
||||||
addPluginArgument(ANNOTATIONS_PLUGIN_NAME, "inherited", true.toString())
|
addPluginArgument(ANNOTATIONS_PLUGIN_NAME, SubpluginOption("inherited", true.toString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user