[Gradle, JS] Manually singleton because Gradle Daemon

^KT-39210 fixed
^KT-31669 fixed
This commit is contained in:
Ilya Goncharov
2020-05-28 11:49:02 +03:00
parent 59c2bc25d5
commit 9fd211cfcd
@@ -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)
}
}
}