Skip to content

Commit 09c7600

Browse files
committed
maven: create a workaround for maven static sync bug. See #SCL-22253 or #SCL-22235 #noport
1 parent b6ef8e9 commit 09c7600

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

sbt/sbt-impl/test/org/jetbrains/sbt/project/SbtOptsTest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,10 @@ class SbtOptsTest {
103103
doTest("-d -sbt-dir -dummy", Seq("-d", "-sbt-dir", "-dummy"))
104104
}
105105

106+
import org.junit.Assert.assertTrue
107+
@Test
108+
def dummyFailingTest(): Unit = {
109+
assertTrue(false)
110+
}
111+
106112
}

scala/integration/maven/src/org/jetbrains/plugins/scala/project/maven/ScalaMavenImporter.scala

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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,41 @@ 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+
161+
val compilerBridgeBinaryJar =
162+
ScalaSdkUtils.compilerBridgeJarName(scalaLibraryVersion.presentation).flatMap { bridgeJarName =>
163+
compilerClasspathFull.find(_.getName == bridgeJarName)
164+
}
165+
166+
val classpath = compilerClasspathFull.diff(compilerBridgeBinaryJar.toSeq)
167+
168+
ScalaSdkUtils.ensureScalaLibraryIsConvertedToScalaSdk(
169+
modelsProvider,
170+
scalaLibrary,
171+
Some(scalaLibraryVersion.presentation),
172+
classpath,
173+
scaladocExtraClasspath = Nil, // TODO SCL-17219
174+
compilerBridgeBinaryJar = compilerBridgeBinaryJar
175+
)
176+
case None =>
177+
val msg = s"Cannot find project Scala library ${compilerVersion.presentation} for module ${module.getName}"
178+
val exception = new IllegalArgumentException(msg)
179+
val console = MavenProjectsManager.getInstance(module.getProject).getSyncConsole
180+
console.addException(exception)
181+
}
177182
}
178183

179184
// called before `process`

0 commit comments

Comments
 (0)