Add support for android MPP

#KT-18462 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-12-08 13:07:43 +01:00
parent 2a10d8e837
commit 7b212c5650
18 changed files with 156 additions and 2 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.gradle.plugin
import com.android.build.gradle.BaseExtension
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
@@ -114,12 +115,12 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
commonProject.sourceSets.all { commonSourceSet ->
// todo: warn if not found
addCommonSourceSetToPlatformSourceSet(commonSourceSet)
addCommonSourceSetToPlatformSourceSet(commonSourceSet, platformProject)
}
}
}
protected open fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet) {
protected open fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet, platformProject: Project) {
val platformTask = platformKotlinTasksBySourceSetName[commonSourceSet.name]
commonSourceSet.kotlin!!.srcDirs.forEach { platformTask?.source(it) }
}
@@ -147,6 +148,20 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
}
}
open class KotlinPlatformAndroidPlugin : KotlinPlatformImplementationPluginBase("android") {
override fun apply(project: Project) {
project.applyPlugin<KotlinAndroidPluginWrapper>()
super.apply(project)
}
override fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet, platformProject: Project) {
val androidExtension = platformProject.extensions.getByName("android") as BaseExtension
val androidSourceSet = androidExtension.sourceSets.findByName(commonSourceSet.name) ?: return
val kotlinSourceSet = androidSourceSet.getConvention(KOTLIN_DSL_NAME) as? KotlinSourceSet ?: return
kotlinSourceSet.kotlin.source(commonSourceSet.kotlin!!)
}
}
open class KotlinPlatformJvmPlugin : KotlinPlatformImplementationPluginBase("jvm") {
override fun apply(project: Project) {
project.applyPlugin<KotlinPluginWrapper>()
@@ -0,0 +1 @@
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinPlatformAndroidPlugin
@@ -0,0 +1 @@
implementation-class=org.jetbrains.kotlin.gradle.plugin.KotlinPlatformAndroidPlugin