问题:
* 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已足够大。