'Scala code compiles through command-line sbt but fails when compiled through Intellij Idea - how set up Intellij to use external sbt?
I'm writing a parser in pure Scala with IntelliJ Idea CE (version 2019.3.4) on macOS (version 10.15.4 at time of posting). The project is set up as an sbt project.
When I compile and test the project through the command line by running sbt
, then compile
, then test
(or just sbt
then test
), everything works fine. The code compiles as expected, and all tests pass.
However, when I attempt to compile the code through the IntelliJ GUI, I get the following error message:
Error:scala: Error while emitting Protobuf3Parser.scala
assertion failed: Invalid interfaces in LPredefinedType;: List(LFieldType;, Lscala/Product;)
The problem piece of code seems to be
sealed trait FieldType
case class PredefinedType(t: DataType) extends FieldType
case class UserDefinedType(t: FullIdent) extends FieldType
where DataType
is a sealed trait
and FullIdent
is a case class
.
The output of this error looks similar to the output produced with this bug from the official Scala language repository: https://github.com/scala/bug/issues/10107. While I am not an expert on Scala internals, the error I received appears to be an issue with the way Scala represents its type system on the JVM.
According to a colleague more familiar with Scala than I, JetBrains has their own implementation of the compilers they use within IntelliJ itself, and sometimes its behavior diverges from the official Scala implementation - which would explain what's occurring here.
Is there any way to configure IntelliJ to use an external sbt and scalac version?
Or does this error come from somewhere else?
I've tried quite a few Google searches and have looked through and experimented with different IntelliJ settings, but to no avail.
Solution 1:[1]
There is a way. Go to Settings, drill down through 'Build,Execution,Deployment' + 'Build Tools' + 'sbt', and there you will find on a per project basis the ability to choose whether to use sbt ('sbt shell') for builds.
Solution 2:[2]
Bit late in the day, but I tried for two hours and in the end I clicked on the bottom on build and the on Sync and magic voila it added the External Libraries and it worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mtk |
Solution 2 | Julia |