gradle compileScala 出現 java.lang.StackOverflowError (no error message)

問題:

* What went wrong:
Execution failed for task ':data-model:compileScala'.
> java.lang.StackOverflowError (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.9/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 42s
2 actionable tasks: 2 executed
Cause: java.lang.StackOverflowError
	at scala.tools.nsc.typechecker.Contexts$Context.make(Contexts.scala:467)
	at scala.tools.nsc.typechecker.Contexts$Context.makeSilent(Contexts.scala:515)
	at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:675)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4558)
    。。。。。。

原因:

scala case class 字段太多,我的有一百多個字段,導致棧溢出。

解決方案:

在build.gradle增加如下配製 :

    compileScala {
        options.fork = true
        options.forkOptions.jvmArgs += ["-Xss8M"]
    }

查找問題原因:

可以找到你的case class 字段最多的那個,然後用scalac xxx.scala單獨編譯,如果是和這個一樣的問題,就會報java.lang.StackOverflowError (no error message), 然後再次執行scalac -JXss8M xxx.scala 應該就不會再保錯。

默認的棧空間是1M, 給8M已足夠大。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章