diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt index 896ded15e03..3351f50f308 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt @@ -13,7 +13,7 @@ import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsPr import com.intellij.openapi.module.Module import com.intellij.openapi.roots.* import com.intellij.openapi.roots.impl.libraries.LibraryEx -import com.intellij.openapi.roots.libraries.Library +import com.intellij.openapi.util.Disposer import com.intellij.util.PathUtil import org.jdom.Element import org.jdom.Text @@ -119,14 +119,18 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ val artifacts = mavenProject.dependencyArtifactIndex.data[KOTLIN_PLUGIN_GROUP_ID]?.values?.flatMap { it.filter { it.isResolved } } ?: emptyList() - val librariesWithNoSources = ArrayList() + val libraryNames = mutableSetOf() OrderEnumerator.orderEntries(module).forEachLibrary { library -> - if (library.modifiableModel.getFiles(OrderRootType.SOURCES).isEmpty()) { - librariesWithNoSources.add(library) + val model = library.modifiableModel + try { + if (model.getFiles(OrderRootType.SOURCES).isEmpty()) { + libraryNames.add(library.name) + } + } finally { + Disposer.dispose(model) } true } - val libraryNames = librariesWithNoSources.mapTo(HashSet()) { it.name } val toBeDownloaded = artifacts.filter { it.libraryName in libraryNames } if (toBeDownloaded.isNotEmpty()) {