From 9fd211cfcdb8e1a2b7c145a6cf5130ae0c262c71 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Thu, 28 May 2020 11:49:02 +0300 Subject: [PATCH] [Gradle, JS] Manually singleton because Gradle Daemon ^KT-39210 fixed ^KT-31669 fixed --- .../js/MultiplePluginDeclarationDetector.kt | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/MultiplePluginDeclarationDetector.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/MultiplePluginDeclarationDetector.kt index 5e9d4c6da77..1262ebdd4cc 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/MultiplePluginDeclarationDetector.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/MultiplePluginDeclarationDetector.kt @@ -6,10 +6,12 @@ package org.jetbrains.kotlin.gradle.targets.js import org.gradle.api.Project +import org.gradle.api.invocation.Gradle import org.jetbrains.kotlin.gradle.plugin.KotlinPluginInMultipleProjectsHolder import org.jetbrains.kotlin.gradle.plugin.MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING -internal object MultiplePluginDeclarationDetector { +internal class MultiplePluginDeclarationDetector +private constructor() { private val pluginInMultipleProjectsHolder = KotlinPluginInMultipleProjectsHolder( differentVersionsInDifferentProject = false ) @@ -22,4 +24,31 @@ internal object MultiplePluginDeclarationDetector { error(MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING) } } + + // We can't use Kotlin object because we need new instance on each Gradle rebuild + // But if we inside Gradle daemon, Kotlin object will be shared between builds + companion object { + @field:Volatile + private var instance: MultiplePluginDeclarationDetector? = null + + @JvmStatic + @Synchronized + private fun getInstance(gradle: Gradle): MultiplePluginDeclarationDetector { + if (instance != null) { + return instance!! + } + + val detector = MultiplePluginDeclarationDetector() + instance = detector + gradle.buildFinished { + instance = null + } + + return detector + } + + fun detect(project: Project) { + getInstance(project.gradle).detect(project) + } + } } \ No newline at end of file