[gradle-plugin] Fix KNPE in mpp plugin
This commit is contained in:
committed by
Ilya Matveev
parent
deee714be8
commit
98785874e0
@@ -1,5 +1,5 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.2.31'
|
ext.kotlin_version = '1.3-M2'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
allprojects {
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
maven { url "http://dl.bintray.com/kotlin/kotlin-eap" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "http://dl.bintray.com/kotlin/kotlin-eap" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task build {
|
task build {
|
||||||
subprojects.each {
|
subprojects.each {
|
||||||
dependsOn("${it.path}:build")
|
dependsOn("${it.path}:build")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.2.31'
|
ext.kotlin_version = '1.3-M2'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.2.31'
|
ext.kotlin_version = '1.3-M2'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
+24
-47
@@ -1,63 +1,40 @@
|
|||||||
package org.jetbrains.kotlin.gradle.plugin
|
package org.jetbrains.kotlin.gradle.plugin
|
||||||
|
|
||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
|
import org.gradle.api.Named
|
||||||
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.ProjectDependency
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.plugins.JavaPluginConvention
|
|
||||||
import org.gradle.api.tasks.SourceSetContainer
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileTask
|
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileTask
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
open class KotlinNativePlatformPlugin: KotlinPlatformImplementationPluginBase("native") {
|
open class KotlinNativePlatformPlugin: KotlinPlatformImplementationPluginBase("native") {
|
||||||
|
|
||||||
protected val commonProjects = arrayListOf<Project>()
|
private val Project.konanMultiplatformTasks: Collection<KonanCompileTask>
|
||||||
|
get() = tasks.withType(KonanCompileTask::class.java).filter { it.enableMultiplatform }
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun configurationsForCommonModuleDependency(project: Project) = emptyList<Configuration>()
|
||||||
val expectedByConfig = project.configurations.create(EXPECTED_BY_CONFIG_NAME)
|
|
||||||
expectedByConfig.isTransitive = false
|
open class RequestedCommonSourceSet @Inject constructor(private val name: String): Named {
|
||||||
expectedByConfig.dependencies.whenObjectAdded { dep ->
|
override fun getName() = name
|
||||||
if (dep is ProjectDependency) {
|
|
||||||
addCommonProject(dep.dependencyProject, project)
|
|
||||||
} else {
|
|
||||||
throw GradleException("$project '${expectedByConfig.name}' dependency is not a project: $dep")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun <T> Project.whenEvaluated(fn: Project.() -> T) {
|
override fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: Named, platformProject: Project) {
|
||||||
if (state.executed) {
|
val commonSourceSetName = commonSourceSet.name
|
||||||
fn()
|
|
||||||
} else {
|
platformProject.konanMultiplatformTasks
|
||||||
afterEvaluate { it.fn() }
|
.filter { it.commonSourceSets.contains(commonSourceSetName) }
|
||||||
}
|
.forEach { task: KonanCompileTask ->
|
||||||
|
getKotlinSourceDirectorySetSafe(commonSourceSet)!!.srcDirs.forEach {
|
||||||
|
task.commonSrcDir(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun addCommonProject(commonProject: Project, platformProject: Project) {
|
override fun namedSourceSetsContainer(project: Project): NamedDomainObjectContainer<*> =
|
||||||
commonProjects.add(commonProject)
|
project.container(RequestedCommonSourceSet::class.java).apply {
|
||||||
commonProject.whenEvaluated {
|
project.konanMultiplatformTasks.forEach { task ->
|
||||||
if (!commonProject.pluginManager.hasPlugin("kotlin-platform-common")) {
|
task.commonSourceSets.forEach { maybeCreate(it) }
|
||||||
throw GradleException("Platform project $platformProject has an " +
|
|
||||||
"'$EXPECTED_BY_CONFIG_NAME' dependency to non-common project $commonProject")
|
|
||||||
}
|
|
||||||
|
|
||||||
platformProject.tasks
|
|
||||||
.withType(KonanCompileTask::class.java)
|
|
||||||
.filter { it.enableMultiplatform }
|
|
||||||
.forEach { task: KonanCompileTask ->
|
|
||||||
task.commonSourceSets.forEach { commonSourceSetName ->
|
|
||||||
val commonSourceSet = commonProject.sourceSets.findByName(commonSourceSetName) ?:
|
|
||||||
throw GradleException("Cannot find a source set with name '$commonSourceSetName' " +
|
|
||||||
"in a common project '${commonProject.path}' " +
|
|
||||||
"for an artifact '${task.artifactName}' " +
|
|
||||||
"in a platform project '${platformProject.path}'")
|
|
||||||
|
|
||||||
commonSourceSet.kotlin!!.srcDirs.forEach {
|
|
||||||
task.commonSrcDir(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected val Project.sourceSets: SourceSetContainer
|
|
||||||
get() = convention.getPlugin(JavaPluginConvention::class.java).sourceSets
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.test
|
package org.jetbrains.kotlin.gradle.plugin.test
|
||||||
|
|
||||||
|
import spock.lang.Ignore
|
||||||
|
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
|
||||||
@@ -315,6 +317,7 @@ class MultiplatformSpecification extends BaseKonanSpecification {
|
|||||||
result.output.contains("has an 'expectedBy' dependency to non-common project")
|
result.output.contains("has an 'expectedBy' dependency to non-common project")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore("TODO in the Big Kotlin plugin")
|
||||||
def 'Build should fail if custom common source set doesn\'t exist'() {
|
def 'Build should fail if custom common source set doesn\'t exist'() {
|
||||||
when:
|
when:
|
||||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||||
|
|||||||
Reference in New Issue
Block a user