@@ -118,7 +118,7 @@ final class ScalaMavenImporter extends MavenImporter("org.scala-tools", "maven-s
118118 *
119119 * @see [[implicitScalaLibraryIfNeeded ]]
120120 */
121- val scalaLibraryToMarkAsSdk : Option [(Library , Version )] = {
121+ val scalaLibraryToMarkAsSdk : Either [ Unit , Option [(Library , Version )] ] = {
122122 val expectedLibraryName = scalaCompilerArtifactName(" library" , compilerVersion.presentation)
123123 val moduleModel = modelsProvider.getModifiableRootModel(module)
124124
@@ -144,36 +144,42 @@ final class ScalaMavenImporter extends MavenImporter("org.scala-tools", "maven-s
144144 librariesWithSameMajorVersion.maxByOption(_._2)
145145 }
146146
147- libraryEntriesGroupedByScope.iterator
148- .flatMap { case _ -> entries => selectScalaLibrary(entries) }
149- .nextOption()
147+ // TODO - this workaround should be removed when #IDEA-348826 is merged to IDEA 2024.1 (around 20.04)
148+ if (libraryEntriesGroupedByScope.isEmpty) Left (())
149+ else {
150+ val selectedLibrary = libraryEntriesGroupedByScope.iterator
151+ .flatMap { case _ -> entries => selectScalaLibrary(entries) }
152+ .nextOption()
153+ Right (selectedLibrary)
154+ }
150155 }
151156
152- scalaLibraryToMarkAsSdk match {
153- case Some ((scalaLibrary, scalaLibraryVersion)) =>
154- val compilerClasspathFull = module.getProject.getUserData(MavenFullCompilerClasspathKey )
155-
156- val compilerBridgeBinaryJar =
157- ScalaSdkUtils .compilerBridgeJarName(scalaLibraryVersion.presentation).flatMap { bridgeJarName =>
158- compilerClasspathFull.find(_.getName == bridgeJarName)
159- }
160-
161- val classpath = compilerClasspathFull.diff(compilerBridgeBinaryJar.toSeq)
162-
163- ScalaSdkUtils .ensureScalaLibraryIsConvertedToScalaSdk(
164- modelsProvider,
165- scalaLibrary,
166- Some (scalaLibraryVersion.presentation),
167- classpath,
168- scaladocExtraClasspath = Nil , // TODO SCL-17219
169- compilerBridgeBinaryJar = compilerBridgeBinaryJar
170- )
171- case None =>
172- val msg = s " Cannot find project Scala library ${compilerVersion.presentation} for module ${module.getName}"
173- val exception = new IllegalArgumentException (msg)
174- val console = MavenProjectsManager .getInstance(module.getProject).getSyncConsole
175- console.addException(exception)
176- }
157+ scalaLibraryToMarkAsSdk.foreach {
158+ case Some ((scalaLibrary, scalaLibraryVersion)) =>
159+ val compilerClasspathFull = module.getProject.getUserData(MavenFullCompilerClasspathKey )
160+ if (compilerClasspathFull == null ) return
161+
162+ val compilerBridgeBinaryJar =
163+ ScalaSdkUtils .compilerBridgeJarName(scalaLibraryVersion.presentation).flatMap { bridgeJarName =>
164+ compilerClasspathFull.find(_.getName == bridgeJarName)
165+ }
166+
167+ val classpath = compilerClasspathFull.diff(compilerBridgeBinaryJar.toSeq)
168+
169+ ScalaSdkUtils .ensureScalaLibraryIsConvertedToScalaSdk(
170+ modelsProvider,
171+ scalaLibrary,
172+ Some (scalaLibraryVersion.presentation),
173+ classpath,
174+ scaladocExtraClasspath = Nil , // TODO SCL-17219
175+ compilerBridgeBinaryJar = compilerBridgeBinaryJar
176+ )
177+ case None =>
178+ val msg = s " Cannot find project Scala library ${compilerVersion.presentation} for module ${module.getName}"
179+ val exception = new IllegalArgumentException (msg)
180+ val console = MavenProjectsManager .getInstance(module.getProject).getSyncConsole
181+ console.addException(exception)
182+ }
177183 }
178184
179185 // called before `process`
0 commit comments