Add kotlin-annotation-processing dependency automatically in kotlinApt configurations
This commit is contained in:
+16
-6
@@ -280,6 +280,9 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
|
|
||||||
val aptConfigurations = hashMapOf<String, Configuration>()
|
val aptConfigurations = hashMapOf<String, Configuration>()
|
||||||
|
|
||||||
|
val projectVersion = loadKotlinVersionFromResource(log)
|
||||||
|
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion"
|
||||||
|
|
||||||
ext.getSourceSets().all(Action<AndroidSourceSet> { sourceSet ->
|
ext.getSourceSets().all(Action<AndroidSourceSet> { sourceSet ->
|
||||||
if (sourceSet is HasConvention) {
|
if (sourceSet is HasConvention) {
|
||||||
val sourceSetName = sourceSet.getName()
|
val sourceSetName = sourceSet.getName()
|
||||||
@@ -292,7 +295,9 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
"kotlinApt${sourceSet.getName().capitalize()}"
|
"kotlinApt${sourceSet.getName().capitalize()}"
|
||||||
} else "kotlinApt"
|
} else "kotlinApt"
|
||||||
|
|
||||||
aptConfigurations.put(sourceSet.getName(), project.getConfigurations().create(aptConfigurationName))
|
val aptConfiguration = project.getConfigurations().create(aptConfigurationName)
|
||||||
|
aptConfiguration.getDependencies().add(project.getDependencies().create(kotlinAnnotationProcessingDep))
|
||||||
|
aptConfigurations.put(sourceSet.getName(), aptConfiguration)
|
||||||
|
|
||||||
/*TODO: before 0.11 gradle android plugin there was:
|
/*TODO: before 0.11 gradle android plugin there was:
|
||||||
sourceSet.getAllJava().source(kotlinDirSet)
|
sourceSet.getAllJava().source(kotlinDirSet)
|
||||||
@@ -313,10 +318,8 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
val plugin = (project.getPlugins().findPlugin("android")
|
val plugin = (project.getPlugins().findPlugin("android")
|
||||||
?: project.getPlugins().findPlugin("android-library")) as BasePlugin
|
?: project.getPlugins().findPlugin("android-library")) as BasePlugin
|
||||||
|
|
||||||
val aptConfigurationDependencyFiles = aptConfigurations.mapValues { it.getValue().resolve() }
|
|
||||||
|
|
||||||
processVariantData(plugin.getVariantManager().getVariantDataList(), project,
|
processVariantData(plugin.getVariantManager().getVariantDataList(), project,
|
||||||
ext, plugin, aptConfigurationDependencyFiles)
|
ext, plugin, aptConfigurations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +332,7 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
project: Project,
|
project: Project,
|
||||||
androidExt: BaseExtension,
|
androidExt: BaseExtension,
|
||||||
androidPlugin: BasePlugin,
|
androidPlugin: BasePlugin,
|
||||||
aptConfigurations: Map<String, Set<File>>
|
aptConfigurations: Map<String, Configuration>
|
||||||
) {
|
) {
|
||||||
val logger = project.getLogger()
|
val logger = project.getLogger()
|
||||||
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
||||||
@@ -386,7 +389,12 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
kotlinTask.source(kotlinSourceDirectorySet)
|
kotlinTask.source(kotlinSourceDirectorySet)
|
||||||
|
|
||||||
kotlinSourceDirectorySet.addSourceDirectories(javaSrcDirs)
|
kotlinSourceDirectorySet.addSourceDirectories(javaSrcDirs)
|
||||||
aptFiles.addAll(aptConfigurations[(provider as AndroidSourceSet).getName()])
|
|
||||||
|
val aptConfiguration = aptConfigurations[(provider as AndroidSourceSet).getName()]
|
||||||
|
// Ignore if there's only an annotation processor wrapper in dependencies (added by default)
|
||||||
|
if (aptConfiguration != null && aptConfiguration.getDependencies().size() > 1) {
|
||||||
|
aptFiles.addAll(aptConfiguration.resolve())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
||||||
@@ -423,6 +431,8 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
|||||||
val result = (obj as HasConvention).getConvention().getPlugins()[extensionName]
|
val result = (obj as HasConvention).getConvention().getPlugins()[extensionName]
|
||||||
return result as T
|
return result as T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadSubplugins(project: Project, logger: Logger): SubpluginEnvironment {
|
private fun loadSubplugins(project: Project, logger: Logger): SubpluginEnvironment {
|
||||||
|
|||||||
+1
-18
@@ -25,7 +25,7 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinPluginVersion = loadKotlinVersionFromResource()
|
val kotlinPluginVersion = loadKotlinVersionFromResource(log)
|
||||||
project.getExtensions().getExtraProperties()?.set("kotlin.gradle.plugin.version", kotlinPluginVersion)
|
project.getExtensions().getExtraProperties()?.set("kotlin.gradle.plugin.version", kotlinPluginVersion)
|
||||||
|
|
||||||
val pluginClassLoader = createPluginIsolatedClassLoader(kotlinPluginVersion, sourceBuildScript)
|
val pluginClassLoader = createPluginIsolatedClassLoader(kotlinPluginVersion, sourceBuildScript)
|
||||||
@@ -56,23 +56,6 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
|
|||||||
return kotlinPluginClassloader
|
return kotlinPluginClassloader
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadKotlinVersionFromResource(): String {
|
|
||||||
log.debug("Loading version information")
|
|
||||||
val props = Properties()
|
|
||||||
val propFileName = "project.properties"
|
|
||||||
val inputStream = this.javaClass.getClassLoader()!!.getResourceAsStream(propFileName)
|
|
||||||
|
|
||||||
if (inputStream == null) {
|
|
||||||
throw FileNotFoundException("property file '" + propFileName + "' not found in the classpath")
|
|
||||||
}
|
|
||||||
|
|
||||||
props.load(inputStream)
|
|
||||||
|
|
||||||
val projectVersion = props["project.version"] as String
|
|
||||||
log.debug("Found project version [$projectVersion]")
|
|
||||||
return projectVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findSourceBuildScript(project: Project): ScriptHandler? {
|
private fun findSourceBuildScript(project: Project): ScriptHandler? {
|
||||||
log.debug("Looking for proper script handler")
|
log.debug("Looking for proper script handler")
|
||||||
var curProject = project
|
var curProject = project
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.plugin
|
||||||
|
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
private fun Any.loadKotlinVersionFromResource(log: Logger): String {
|
||||||
|
log.debug("Loading version information")
|
||||||
|
val props = Properties()
|
||||||
|
val propFileName = "project.properties"
|
||||||
|
val inputStream = javaClass.getClassLoader()!!.getResourceAsStream(propFileName)
|
||||||
|
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw FileNotFoundException("property file '" + propFileName + "' not found in the classpath")
|
||||||
|
}
|
||||||
|
|
||||||
|
props.load(inputStream)
|
||||||
|
|
||||||
|
val projectVersion = props["project.version"] as String
|
||||||
|
log.debug("Found project version [$projectVersion]")
|
||||||
|
return projectVersion
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user