diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt index cf3e3e05b2236..a286962d86d57 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.registerDefaultVariantFactori import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.setupFragmentsMetadataForKpmModules import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.setupKpmModulesPublication import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.copyAttributes -import org.jetbrains.kotlin.gradle.plugin.sources.CleanupStaleSourceSetMetadataEntriesService import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetMetadataStorageForIde import org.jetbrains.kotlin.gradle.plugin.sources.checkSourceSetVisibilityRequirements @@ -126,24 +125,6 @@ class KotlinMultiplatformPlugin : Plugin { project.pluginManager.apply(ScriptingGradleSubplugin::class.java) exportProjectStructureMetadataForOtherBuilds(project) - - SingleActionPerBuild.run(project.rootProject, "cleanup-processed-metadata") { - if (isConfigurationCacheAvailable(project.gradle)) { - BuildEventsListenerRegistryHolder.getInstance(project).listenerRegistry.onTaskCompletion( - project.gradle.sharedServices - .registerIfAbsent( - "cleanup-stale-sourceset-metadata", - CleanupStaleSourceSetMetadataEntriesService::class.java - ) { - CleanupStaleSourceSetMetadataEntriesService.configure(it, project) - } - ) - } else { - project.gradle.buildFinished { - SourceSetMetadataStorageForIde.cleanupStaleEntries(project) - } - } - } } private fun exportProjectStructureMetadataForOtherBuilds( diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/SourceSetMetadataStorageForIde.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/SourceSetMetadataStorageForIde.kt index 67c15bc3f5e07..9f32202f5a3eb 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/SourceSetMetadataStorageForIde.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/SourceSetMetadataStorageForIde.kt @@ -17,31 +17,9 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull import java.io.File object SourceSetMetadataStorageForIde { - fun cleanupStaleEntries(project: Project) { - val projectStorageDirectories = project.rootProject.allprojects - .associate { projectStorage(it) to it.multiplatformExtensionOrNull?.sourceSets.orEmpty().map { it.name } } - cleanupStaleEntries(getStorageRoot(project), projectStorageDirectories) - } - - fun cleanupStaleEntries(projectStorageRoot: File, projectStorageDirectories: Map>) { - projectStorageRoot.listFiles().orEmpty().filter { it.isDirectory }.forEach { directory -> - // If no project corresponds to the directory, remove the directory - if (directory !in projectStorageDirectories) { - directory.deleteRecursively() - } else { - // Under the project's directory, delete subdirectories that don't correspond to any source set: - val sourceSetNames = projectStorageDirectories.getValue(directory) - directory.listFiles().orEmpty().filter { it.isDirectory }.forEach { subdirectory -> - if (subdirectory.name !in sourceSetNames) - subdirectory.deleteRecursively() - } - } - } - } + private fun getStorageRoot(project: Project): File = project.rootDir.resolve(".gradle/kotlin/sourceSetMetadata") - internal fun getStorageRoot(project: Project): File = project.rootDir.resolve(".gradle/kotlin/sourceSetMetadata") - - internal fun projectStorage(project: Project): File { + private fun projectStorage(project: Project): File { val projectPathSegments = generateSequence(project) { it.parent }.map { it.name } return getStorageRoot(project).resolve( // Escape dots in project names to avoid ambiguous paths. @@ -54,27 +32,3 @@ object SourceSetMetadataStorageForIde { internal fun sourceSetStorageWithScope(project: Project, sourceSetName: String, scope: KotlinDependencyScope) = sourceSetStorage(project, sourceSetName).resolve(scope.scopeName) } - -abstract class CleanupStaleSourceSetMetadataEntriesService : BuildService, AutoCloseable, OperationCompletionListener { - interface Parameters : BuildServiceParameters { - val projectStorageRoot: Property - val projectStorageDirectories: MapProperty> - } - - override fun onFinish(event: FinishEvent?) { - // noop - } - - override fun close() { - SourceSetMetadataStorageForIde.cleanupStaleEntries(parameters.projectStorageRoot.get(), parameters.projectStorageDirectories.get()) - } - - companion object { - fun configure(spec: BuildServiceSpec, project: Project) { - spec.parameters.projectStorageRoot.set(SourceSetMetadataStorageForIde.getStorageRoot(project)) - spec.parameters.projectStorageDirectories.set(project.rootProject.allprojects.associate { - SourceSetMetadataStorageForIde.projectStorage(it) to it.multiplatformExtensionOrNull?.sourceSets.orEmpty().map { it.name } - }) - } - } -} \ No newline at end of file