kapt: Support inherited annotations in Gradle
This commit is contained in:
+19
-11
@@ -131,17 +131,7 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
val basePluginOptions = extraProperties.getOrNull<Array<String>>("compilerPluginArguments") ?: arrayOf()
|
||||
|
||||
val pluginOptions = arrayListOf(*basePluginOptions)
|
||||
|
||||
val kaptAnnotationsFile = extraProperties.getOrNull<File>("kaptAnnotationsFile")
|
||||
if (kaptAnnotationsFile != null) {
|
||||
if (kaptAnnotationsFile.exists()) kaptAnnotationsFile.delete()
|
||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:output=" + kaptAnnotationsFile)
|
||||
}
|
||||
|
||||
val kaptClassFileStubsDir = extraProperties.getOrNull<File>("stubsDir")
|
||||
if (kaptClassFileStubsDir != null) {
|
||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir)
|
||||
}
|
||||
handleKaptProperties(extraProperties, pluginOptions)
|
||||
|
||||
args.pluginOptions = pluginOptions.toTypedArray()
|
||||
getLogger().kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}")
|
||||
@@ -162,6 +152,24 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
args.noParamAssertions = kotlinOptions.noParamAssertions
|
||||
}
|
||||
|
||||
private fun handleKaptProperties(extraProperties: ExtraPropertiesExtension, pluginOptions: MutableList<String>) {
|
||||
val kaptAnnotationsFile = extraProperties.getOrNull<File>("kaptAnnotationsFile")
|
||||
if (kaptAnnotationsFile != null) {
|
||||
if (kaptAnnotationsFile.exists()) kaptAnnotationsFile.delete()
|
||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:output=" + kaptAnnotationsFile)
|
||||
}
|
||||
|
||||
val kaptClassFileStubsDir = extraProperties.getOrNull<File>("kaptStubsDir")
|
||||
if (kaptClassFileStubsDir != null) {
|
||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir)
|
||||
}
|
||||
|
||||
val supportInheritedAnnotations = extraProperties.getOrNull<Boolean>("kaptInheritedAnnotations")
|
||||
if (supportInheritedAnnotations != null && supportInheritedAnnotations) {
|
||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:inherited=true")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getJavaSourceRoots(): Set<File> =
|
||||
getSource()
|
||||
.filter { it.isJavaFile() }
|
||||
|
||||
+2
@@ -23,6 +23,8 @@ public open class KaptExtension {
|
||||
|
||||
public open var generateStubs: Boolean = false
|
||||
|
||||
public open var inheritedAnnotations: Boolean = true
|
||||
|
||||
private var closure: Closure<*>? = null
|
||||
|
||||
public open fun arguments(closure: Closure<*>) {
|
||||
|
||||
+10
-3
@@ -536,7 +536,7 @@ private class SubpluginEnvironment(
|
||||
}
|
||||
}
|
||||
|
||||
val extraProperties = compileTask.getExtensions().getExtraProperties()
|
||||
val extraProperties = compileTask.extraProperties
|
||||
extraProperties.set("compilerPluginClasspaths", realPluginClasspaths.toTypedArray())
|
||||
extraProperties.set("compilerPluginArguments", pluginArguments.toTypedArray())
|
||||
}
|
||||
@@ -563,7 +563,7 @@ open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInt
|
||||
}
|
||||
|
||||
private fun AbstractCompile.storeKaptAnnotationsFile(kapt: AnnotationProcessingManager) {
|
||||
getExtensions().getExtraProperties().set("kaptAnnotationsFile", kapt.getAnnotationFile())
|
||||
extraProperties.set("kaptAnnotationsFile", kapt.getAnnotationFile())
|
||||
}
|
||||
|
||||
private fun Project.getAptDirsForSourceSet(kotlinTask: AbstractCompile, sourceSetName: String): Pair<File, File> {
|
||||
@@ -607,7 +607,7 @@ private fun Project.initKapt(
|
||||
kotlinTask.getLogger().kotlinDebug("kapt: Using class file stubs")
|
||||
|
||||
val stubsDir = File(getBuildDir(), "tmp/kapt/$variantName/classFileStubs")
|
||||
kotlinTask.getExtensions().getExtraProperties().set("stubsDir", stubsDir)
|
||||
kotlinTask.extraProperties.set("kaptStubsDir", stubsDir)
|
||||
|
||||
javaTask.setClasspath(javaTask.getClasspath() + files(stubsDir))
|
||||
|
||||
@@ -621,6 +621,10 @@ private fun Project.initKapt(
|
||||
kotlinTask.getLogger().kotlinDebug("kapt: Class file stubs are not used")
|
||||
}
|
||||
|
||||
if (kaptExtension.inheritedAnnotations) {
|
||||
kotlinTask.extraProperties.set("kaptInheritedAnnotations", true)
|
||||
}
|
||||
|
||||
kotlinTask.doFirst {
|
||||
kaptManager.generateJavaHackFile()
|
||||
}
|
||||
@@ -682,6 +686,9 @@ private fun loadAndroidPluginVersion(): String? {
|
||||
}
|
||||
}
|
||||
|
||||
private val AbstractCompile.extraProperties: ExtraPropertiesExtension
|
||||
get() = getExtensions().getExtraProperties()
|
||||
|
||||
//Copied from StringUtil.compareVersionNumbers
|
||||
private fun compareVersionNumbers(v1: String?, v2: String?): Int {
|
||||
if (v1 == null && v2 == null) {
|
||||
|
||||
Reference in New Issue
Block a user