2

I have a sbt project which I have imported into IntelliJ IDEA. This project includes the splain compiler plugin which includes colour codes in some compiler messages.

When compiling in IntelliJ IDEA then these colour codes are not interpreted. I can add "-P:splain:color:false" to the Additional compiler options in Preferences which works but is lost when I refresh the sbt project.

Is there a way to set the scalacOptions in sbt so that it only applies to IntelliJ IDEA?

4

2 回答 2

5

IntelliJ Scala 插件-Didea.managed=true在启动 sbt 实例时设置系统属性,所以这可以工作:

scalacOptions += if (System.getProperty("idea.managed") == "true") {
  "-P:splain:color:false"
} else {
  "-P:splain:color:true"
}
于 2018-07-17T10:41:28.823 回答
0

我找到了解决这个特殊问题的颜色输出和 splain 的解决方案,但它不是scalacOptions仅适用于 IntelliJ IDEA 的通用设置解决方案。

scalacOptions += if (ConsoleAppender.formatEnabledInEnv) {
  "-P:splain:color:true"
} else {
  "-P:splain:color:false"
}

我已经-no-colors在构建过程中运行了 sbt,因此让编译器选项依赖于此是有意义的。这是一个有根据的猜测,这也将解决 IntelliJ IDEA 中的问题。

于 2018-07-17T00:39:15.390 回答