Support android-compiler-plugin in Gradle
This commit is contained in:
@@ -84,6 +84,7 @@
|
||||
<module>tools/kotlin-js-library</module>
|
||||
<module>tools/kotlin-gradle-plugin</module>
|
||||
<module>tools/kotlin-gradle-plugin-core</module>
|
||||
<module>tools/kotlin-android-compiler-plugin</module>
|
||||
<module>tools/kotlin-maven-plugin</module>
|
||||
<module>tools/kotlin-maven-plugin-test</module>
|
||||
<module>tools/kotlin-js-tests</module>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven-plugin-anno.version>1.4.1</maven-plugin-anno.version>
|
||||
<maven.version>3.0.4</maven.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>kotlin-android-compiler-plugin</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<description>Android compiler plugin for Kotlin</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-gradle-plugin-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-artifacts</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>attach-artifact</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<artifact>
|
||||
<file>${kotlin-sdk}/lib/android-compiler-plugin.jar</file>
|
||||
<type>jar</type>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+2
-2
@@ -131,8 +131,8 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
val srcDirsSources = HashSet<SourceDirectorySet>()
|
||||
|
||||
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
||||
args.androidRes = resPath
|
||||
args.androidManifest = manifestPath
|
||||
args.pluginClasspaths = kotlinOptions.pluginClasspaths
|
||||
args.pluginOptions = kotlinOptions.pluginOptions
|
||||
|
||||
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
||||
val existingClasspathEntries = getClasspath().filter({ it != null && it.exists() })
|
||||
|
||||
+17
-3
@@ -37,6 +37,8 @@ import kotlin.properties.Delegates
|
||||
import org.gradle.api.tasks.Delete
|
||||
import groovy.lang.Closure
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
|
||||
|
||||
val DEFAULT_ANNOTATIONS = "org.jebrains.kotlin.gradle.defaultAnnotations"
|
||||
|
||||
@@ -302,6 +304,10 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
||||
project.getExtensions().add(DEFAULT_ANNOTATIONS, GradleUtils(scriptHandler, project).resolveKotlinPluginDependency("kotlin-android-sdk-annotations"))
|
||||
}
|
||||
|
||||
private fun makePluginOption(option: CliOption, value: String): String {
|
||||
return "plugin:${AndroidCommandLineProcessor.ANDROID_COMPILER_PLUGIN_ID}:${option.name}=$value"
|
||||
}
|
||||
|
||||
private fun processVariants(variants: DefaultDomainObjectSet<out BaseVariant>, project: Project, androidExt: BaseExtension): Unit {
|
||||
val logger = project.getLogger()
|
||||
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
||||
@@ -324,6 +330,17 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
||||
val javaTask = variant.getJavaCompile()!!
|
||||
val variantName = variant.getName()
|
||||
|
||||
val resourceDir = AndroidGradleWrapper.getResourceDirs(mainSourceSet).firstOrNull()
|
||||
val manifestFile = AndroidGradleWrapper.getManifestFile(mainSourceSet)
|
||||
|
||||
if (resourceDir != null) {
|
||||
val layoutDir = File(resourceDir, "layout")
|
||||
kotlinOptions.pluginOptions = array(
|
||||
makePluginOption("androidRes", layoutDir.getAbsolutePath()),
|
||||
makePluginOption("androidManifest", manifestFile.getAbsolutePath())
|
||||
)
|
||||
}
|
||||
|
||||
val kotlinTaskName = "compile${variantName.capitalize()}Kotlin"
|
||||
val kotlinTask = tasksProvider.createKotlinJVMTask(project, kotlinTaskName)
|
||||
if (kotlinOptions != null) {
|
||||
@@ -338,9 +355,6 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
||||
kotlinTask.setClasspath(javaTask.getClasspath())
|
||||
kotlinTask.setDependsOn(javaTask.getDependsOn())
|
||||
|
||||
kotlinTask.resPath = File(variant.getMergeResources()?.getOutputDir()!!.canonicalPath + "/layout").canonicalPath
|
||||
kotlinTask.manifestPath = variant.getProcessResources().getManifestFile()!!.canonicalPath
|
||||
|
||||
val javaSourceList = ArrayList<Any?>()
|
||||
|
||||
fun processSourceSet(javaSourceSet: AndroidSourceSet) {
|
||||
|
||||
+10
@@ -46,6 +46,16 @@ class AndroidGradleWrapper {
|
||||
return androidSourceSet.getJava().getSrcDirs()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static def Set<File> getResourceDirs(Object androidSourceSet) {
|
||||
return androidSourceSet.getRes().getSrcDirs()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static def File getManifestFile(Object androidSourceSet) {
|
||||
return androidSourceSet.getManifest().getSrcFile()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static def List<String> getProductFlavorsNames(ApkVariant variant) {
|
||||
return variant.getProductFlavors().iterator().collect { it.getName() }
|
||||
|
||||
Reference in New Issue
Block a user