22

I am trying to build a Scala project on IntelliJ using Gradle. I am able to make but compile keeps failing with a stack overflow error.

I looked through other posts with similar issues which suggested increasing heap/stack size (this and this). So far I have tried setting these in JAVA_OPTS and idea64.exe.vmoptions.

-Xss512m -Xms512m -Xmx2048m -XX:ReservedCodeCacheSize=64m -ea

I also tried including -XX:MaxPermSize=2048m which didn't work either (believe it is not supported in Java 8 anyway).

The same code builds for another person with the same configuration. Can anyone please shed some light on what I am missing?

Details:

IntelliJ Ultimate 2016.1
Scala 2.10.3
Java 1.8.0_92

Stack Trace:

java.lang.StackOverflowError
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:696)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:680)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4522)
    at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4578)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5343)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5360)
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:696)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5472)
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5480)
    at scala.tools.nsc.transform.Erasure$Eraser.adaptMember(Erasure.scala:642)
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:696)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:680)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4522)
    at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4578)
Community
  • 1
  • 1
zzz
  • 363
  • 1
  • 2
  • 9
  • 1
    This exception is from the compiler process, not the process of IDEA itself. Try to increase -Xss in Settings -> Languages & Frameworks -> Scala Compile Server -> JVM Parameters. Also check that Scala compile server is enabled. – niktrop Apr 04 '17 at 13:17

5 Answers5

20

The exception is from the compiler that IntelliJ employs, hence you need to change the compiler build process' heap size. Go to

File -> Settings -> Build, Execution, Deployment -> Compiler -> Build process 
heap size (Mbytes)

Increase this property to a higher value.

Screenshot showing the settings pane increasing the value to 1024 MBytes

ComFreek
  • 29,044
  • 18
  • 104
  • 156
Aaditya Raj
  • 1,078
  • 12
  • 19
19

I've solved this via:

Preferences -> Build, Execution, Deployment -> Compiler -> Scala Compiler -> Scala Compile Server

And updated JVM options to use a bigger stack size, eg: -Xss8m

Restart for the changes to take effect.

tekumara
  • 8,357
  • 10
  • 57
  • 69
4

Adding -Xss100m in eclipse.ini worked in my case, probably adding similar property in intellijJ may help.

ankitbaldua
  • 263
  • 4
  • 14
  • I have raised similar question on below link, please follow that: https://stackoverflow.com/questions/46110844/scala-compiler-stackoverflow-error-when-importing-project?noredirect=1#comment79185015_46110844 – ankitbaldua Sep 13 '17 at 08:53
2

Here is what worked for me:

  • From Windows Powershell, $env:SBT_OPTS="-Xss1024m" and then ran sbt compile

  • Also in IntelliJ v2020.2, following also worked: Settings -> Build, Execution, Deployment -> Build Tools -> SBT -> JVM : VM Parameters : -Xss1024m

0

I had same issues and done lots changes in intellij but non of them work.

I removed unused case classes from my code and its working

Ravi H
  • 596
  • 3
  • 23