[DependencySubstitution] fix: don't deduplicate same library coordinates

The same library coordinates can be associated fo different LibraryEntity instances that points on the same logical libraries. For example Maven and Gradle creates LibraryEntity with different ids, for the same library, because Maven adds the "Maven:" prefix for a library name, Gradle adds "Gradle:".

### Issues
  * IDEA-374892 Library dependencies aren't substituted with different names and same coordinates
  * IDEA-370483 Maven performance degradation related to library dependency substitution


(cherry picked from commit 2c89f84c1374c5d9373eb590df74565713f13de4)

IJ-CR-167051

GitOrigin-RevId: f0a9432e576cd1ab50f991c5c83ea8cb8020c77b
This commit is contained in:
Sergei Vorobyov
2025-06-23 18:18:42 +02:00
committed by intellij-monorepo-bot
parent 8c49d77c1a
commit 642501051d
5 changed files with 95 additions and 21 deletions

View File

@@ -2,7 +2,6 @@
package com.intellij.java.impl.dependencySubstitution
import com.intellij.platform.externalSystem.impl.dependencySubstitution.DependencySubstitutionExtension
import com.intellij.platform.externalSystem.impl.dependencySubstitution.DependencySubstitutionUtil.intersect
import com.intellij.platform.workspace.jps.entities.LibraryId
import com.intellij.platform.workspace.jps.entities.ModuleId
import com.intellij.platform.workspace.storage.EntityStorage
@@ -11,10 +10,12 @@ import com.intellij.platform.workspace.storage.entities
private class MavenCoordinateDependencySubstitutionExtension : DependencySubstitutionExtension {
override fun buildLibraryToModuleMap(storage: EntityStorage): Map<LibraryId, ModuleId> {
val libraries = storage.entities<LibraryMavenCoordinateEntity>()
.associate { it.coordinates to it.library.symbolicId }
val modules = storage.entities<ModuleMavenCoordinateEntity>()
.associate { it.coordinates to it.module.symbolicId }
return libraries.intersect(modules)
val result = HashMap<LibraryId, ModuleId>()
for (library in storage.entities<LibraryMavenCoordinateEntity>()) {
result[library.library.symbolicId] = modules[library.coordinates] ?: continue
}
return result
}
}