Avoid adding common sources to platform source set

If common sources are added to a platform source set,
then IDE sees common src dir as a source root in a platform project,
which is incorrect.
This commit is contained in:
Alexey Tsvetkov
2016-12-16 15:34:25 +03:00
parent c6586f2ac8
commit 6974cdf167
@@ -37,14 +37,14 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) { open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) {
private val commonProjects = arrayListOf<Project>() private val commonProjects = arrayListOf<Project>()
private val platformSourceSets = hashMapOf<String, SourceSet>() private val platformKotlinTasksBySourceSetName = hashMapOf<String, AbstractKotlinCompile<*>>()
override fun apply(project: Project) { override fun apply(project: Project) {
project.tasks.withType(AbstractKotlinCompile::class.java).all { project.tasks.withType(AbstractKotlinCompile::class.java).all {
(it as KotlinCompile<*>).kotlinOptions.freeCompilerArgs += listOf("-Xmulti-platform") (it as KotlinCompile<*>).kotlinOptions.freeCompilerArgs += listOf("-Xmulti-platform")
} }
project.sourceSets.associateByTo(platformSourceSets, SourceSet::getName) project.tasks.filterIsInstance<AbstractKotlinCompile<*>>().associateByTo(platformKotlinTasksBySourceSetName) { it.sourceSetName }
val implementConfig = project.configurations.create("implement") val implementConfig = project.configurations.create("implement")
implementConfig.isTransitive = false implementConfig.isTransitive = false
@@ -71,9 +71,8 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
commonProject.sourceSets.all { commonSourceSet -> commonProject.sourceSets.all { commonSourceSet ->
// todo: warn if not found // todo: warn if not found
val platformSourceSet = platformSourceSets[commonSourceSet.name] val platformTask = platformKotlinTasksBySourceSetName[commonSourceSet.name]
val platformKotlinSourceDirectorySet = platformSourceSet?.kotlin commonSourceSet.kotlin!!.srcDirs.forEach { platformTask?.source(it) }
commonSourceSet.kotlin?.srcDirs?.forEach { platformKotlinSourceDirectorySet?.srcDir(it) }
} }
} }
} }