[Gradle, JS] Throw error in JS part when plugins goes from different classloaders
^KT-39210 fixed ^KT-31669 fixed
This commit is contained in:
+1
-1
@@ -133,7 +133,7 @@ internal class KotlinGradleBuildServices private constructor(
|
|||||||
val onRegister = {
|
val onRegister = {
|
||||||
gradle.taskGraph.whenReady {
|
gradle.taskGraph.whenReady {
|
||||||
if (multipleProjectsHolder.isInMultipleProjects(project, kotlinPluginVersion)) {
|
if (multipleProjectsHolder.isInMultipleProjects(project, kotlinPluginVersion)) {
|
||||||
val loadedInProjects = multipleProjectsHolder.getAffectedProjects(project, kotlinPluginVersion)
|
val loadedInProjects = multipleProjectsHolder.getAffectedProjects(project, kotlinPluginVersion)!!
|
||||||
if (PropertiesProvider(project).ignorePluginLoadedInMultipleProjects != true) {
|
if (PropertiesProvider(project).ignorePluginLoadedInMultipleProjects != true) {
|
||||||
project.logger.warn(MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING)
|
project.logger.warn(MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING)
|
||||||
project.logger.warn(
|
project.logger.warn(
|
||||||
|
|||||||
+25
-16
@@ -16,22 +16,13 @@ internal class KotlinPluginInMultipleProjectsHolder(
|
|||||||
fun addProject(
|
fun addProject(
|
||||||
project: Project,
|
project: Project,
|
||||||
kotlinPluginVersion: String? = null,
|
kotlinPluginVersion: String? = null,
|
||||||
onRegister: () -> Unit
|
onRegister: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
require(differentVersionsInDifferentProject == (kotlinPluginVersion != null))
|
require(differentVersionsInDifferentProject == (kotlinPluginVersion != null))
|
||||||
|
|
||||||
val projectPath = project.path
|
val projectPath = project.path
|
||||||
|
|
||||||
val loadedInProjectsPropertyName = listOf(
|
val loadedInProjectsPropertyName = getPropertyName(kotlinPluginVersion)
|
||||||
"kotlin",
|
|
||||||
"plugin",
|
|
||||||
"loaded",
|
|
||||||
"in",
|
|
||||||
"projects",
|
|
||||||
kotlinPluginVersion
|
|
||||||
)
|
|
||||||
.filterNotNull()
|
|
||||||
.joinToString(".")
|
|
||||||
|
|
||||||
if (!differentVersionsInDifferentProject || loadedInProjectPath == null) {
|
if (!differentVersionsInDifferentProject || loadedInProjectPath == null) {
|
||||||
loadedInProjectPath = projectPath
|
loadedInProjectPath = projectPath
|
||||||
@@ -52,29 +43,47 @@ internal class KotlinPluginInMultipleProjectsHolder(
|
|||||||
kotlinPluginVersion: String? = null
|
kotlinPluginVersion: String? = null
|
||||||
): Boolean {
|
): Boolean {
|
||||||
require(differentVersionsInDifferentProject == (kotlinPluginVersion != null))
|
require(differentVersionsInDifferentProject == (kotlinPluginVersion != null))
|
||||||
return getAffectedProjects(project, kotlinPluginVersion).size > 1
|
return getAffectedProjects(project, kotlinPluginVersion)?.let {
|
||||||
|
it.size > 1
|
||||||
|
} ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAffectedProjects(
|
fun getAffectedProjects(
|
||||||
project: Project,
|
project: Project,
|
||||||
kotlinPluginVersion: String? = null
|
kotlinPluginVersion: String? = null
|
||||||
): List<String> {
|
): List<String>? {
|
||||||
require(differentVersionsInDifferentProject == (kotlinPluginVersion != null))
|
require(differentVersionsInDifferentProject == (kotlinPluginVersion != null))
|
||||||
|
|
||||||
val ext = getExt(project)
|
val ext = getExt(project)
|
||||||
|
|
||||||
val loadedInProjectsPropertyName = "kotlin.plugin.loaded.in.projects.${kotlinPluginVersion}"
|
val propertyName = getPropertyName(kotlinPluginVersion)
|
||||||
|
|
||||||
return (ext.get(loadedInProjectsPropertyName) as String).split(";")
|
if (!ext.has(propertyName)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ext.get(propertyName) as String).split(";")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getExt(project: Project): ExtraPropertiesExtension {
|
private fun getExt(project: Project): ExtraPropertiesExtension {
|
||||||
return project.rootProject.extensions.getByType(ExtraPropertiesExtension::class.java)
|
return project.rootProject.extensions.getByType(ExtraPropertiesExtension::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getPropertyName(version: String?): String {
|
||||||
|
return listOfNotNull(
|
||||||
|
"kotlin",
|
||||||
|
"plugin",
|
||||||
|
"loaded",
|
||||||
|
"in",
|
||||||
|
"projects",
|
||||||
|
version
|
||||||
|
)
|
||||||
|
.joinToString(".")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const val MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING: String =
|
const val MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING: String =
|
||||||
"\nThe Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build. \n" +
|
"The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build. \n" +
|
||||||
|
|
||||||
"This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify " +
|
"This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify " +
|
||||||
"explicit versions, even if the versions are equal.\n" +
|
"explicit versions, even if the versions are equal.\n" +
|
||||||
|
|||||||
+19
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,10 +10,7 @@ import org.gradle.api.Task
|
|||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryType
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryType
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
||||||
@@ -31,6 +28,23 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
private val disambiguationClassifier: String
|
private val disambiguationClassifier: String
|
||||||
) : KotlinJsSubTargetDsl {
|
) : KotlinJsSubTargetDsl {
|
||||||
val project get() = target.project
|
val project get() = target.project
|
||||||
|
|
||||||
|
init {
|
||||||
|
val kotlinPluginInMultipleProjectsHolder = KotlinPluginInMultipleProjectsHolder(
|
||||||
|
differentVersionsInDifferentProject = false
|
||||||
|
)
|
||||||
|
|
||||||
|
val anyProjectAffected = kotlinPluginInMultipleProjectsHolder.getAffectedProjects(project)
|
||||||
|
?.isNotEmpty() ?: false
|
||||||
|
|
||||||
|
if (anyProjectAffected) {
|
||||||
|
error(MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING)
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinPluginInMultipleProjectsHolder
|
||||||
|
.addProject(project)
|
||||||
|
}
|
||||||
|
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
abstract val testTaskDescription: String
|
abstract val testTaskDescription: String
|
||||||
|
|||||||
+19
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,11 +10,8 @@ import org.gradle.api.Task
|
|||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
||||||
@@ -33,6 +30,23 @@ abstract class KotlinJsSubTarget(
|
|||||||
private val disambiguationClassifier: String
|
private val disambiguationClassifier: String
|
||||||
) : KotlinJsSubTargetDsl {
|
) : KotlinJsSubTargetDsl {
|
||||||
val project get() = target.project
|
val project get() = target.project
|
||||||
|
|
||||||
|
init {
|
||||||
|
val kotlinPluginInMultipleProjectsHolder = KotlinPluginInMultipleProjectsHolder(
|
||||||
|
differentVersionsInDifferentProject = false
|
||||||
|
)
|
||||||
|
|
||||||
|
val anyProjectAffected = kotlinPluginInMultipleProjectsHolder.getAffectedProjects(project)
|
||||||
|
?.isNotEmpty() ?: false
|
||||||
|
|
||||||
|
if (anyProjectAffected) {
|
||||||
|
error(MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING)
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinPluginInMultipleProjectsHolder
|
||||||
|
.addProject(project)
|
||||||
|
}
|
||||||
|
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
abstract val testTaskDescription: String
|
abstract val testTaskDescription: String
|
||||||
|
|||||||
Reference in New Issue
Block a user