[Gradle, JS] Make MultiplePluginDeclarationDetector compatible w/ conf cache
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
|
||||
abstract class BuildFinishedListenerService : BuildService<BuildServiceParameters.None>, AutoCloseable {
|
||||
private val actionsOnClose = mutableListOf<() -> Unit>()
|
||||
|
||||
fun onClose(action: () -> Unit) {
|
||||
actionsOnClose.add(action)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
for (action in actionsOnClose) {
|
||||
action()
|
||||
}
|
||||
actionsOnClose.clear()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getInstance(gradle: Gradle): BuildFinishedListenerService {
|
||||
// Use class loader hashcode in case there are multiple class loaders in the same build
|
||||
return gradle.sharedServices
|
||||
.registerIfAbsent(
|
||||
"build-finished-listener_${BuildFinishedListenerService::class.java.classLoader.hashCode()}",
|
||||
BuildFinishedListenerService::class.java
|
||||
) {}.get()
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.gradle.targets.js
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.jetbrains.kotlin.gradle.plugin.BuildFinishedListenerService
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginInMultipleProjectsHolder
|
||||
import org.jetbrains.kotlin.gradle.plugin.MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING
|
||||
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
|
||||
|
||||
internal class MultiplePluginDeclarationDetector
|
||||
private constructor() {
|
||||
@@ -40,9 +42,12 @@ private constructor() {
|
||||
|
||||
val detector = MultiplePluginDeclarationDetector()
|
||||
instance = detector
|
||||
// gradle.buildFinished {
|
||||
// instance = null
|
||||
// }
|
||||
|
||||
if (isConfigurationCacheAvailable(gradle)) {
|
||||
BuildFinishedListenerService.getInstance(gradle).onClose { instance = null }
|
||||
} else {
|
||||
gradle.buildFinished { instance = null }
|
||||
}
|
||||
|
||||
return detector
|
||||
}
|
||||
@@ -51,4 +56,4 @@ private constructor() {
|
||||
getInstance(project.gradle).detect(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user