简体   繁体   English

SBT和Scala-IDE中的同步增量编译

[英]Simultaneous incremental compilation in SBT and Scala-IDE

When I am trying to work with the same project both from SBT command line and from Scala-IDE, building several times in the same way (ie only from the command line or only from the IDE) allows project to be rebuilt incrementally. 当我尝试使用SBT命令行和Scala-IDE中的同一项目时,以相同的方式(即仅从命令行或仅从IDE)构建多次允许以递增方式重建项目。 However, if I compile the project in SBT, I've notices it has to be rebuilt completely in the IDE (and vice versa). 但是,如果我在SBT中编译项目,我注意到它必须在IDE中完全重建(反之亦然)。 Is there any way to avoid it? 有什么办法可以避免吗? If it matters, the Eclipse project is generated from SBT using sbteclipse. 如果重要,Eclipse项目将使用sbteclipse从SBT生成。

For me the problem when running ScalaIDE and sbt ~compile simultaneously turned out to be the fact, that both ScalaIDE and sbt used the same output directory for their compilation. 对我来说,同时运行ScalaIDE和sbt~compile时的问题原因是ScalaIDE和sbt都使用相同的输出目录进行编译。 This meant that they overwrote each others compiled classes and would detect them as changed resulting in new complete recompile instead of using incremental compile. 这意味着他们覆盖了彼此编译的类,并将其检测为已更改,从而导致新的完全重新编译,而不是使用增量编译。

To fix it change the output directory of one of the compilers doing one of the following: 要修复它,请更改其中一个编译器的输出目录,执行以下操作之一:

  • manually edit: Project Properties -> Java Build Path -> locate the scala source folder for both, main and tests (usually [project]/src/[test/main]/scala) and edit their output folder to be something else than the default (eg to [project]/target/eclipse) 手动编辑:项目属性 - > Java构建路径 - >找到两个,主要和测试(通常是[project] / src / [test / main] / scala)的scala源文件夹,并将其输出文件夹编辑为除了默认(例如[project] / target / eclipse)
  • add to your build.sbt the following directive: 添加到build.sbt以下指令:

      EclipseKeys.eclipseOutput := Some("target/eclipse") 

Both will change the compile output directory of the ScalaIDE compiler to [project]/target/eclipse , where project should be the actual name of your project directory. 两者都会将ScalaIDE编译器的编译输出目录更改为[project]/target/eclipse ,其中project应该是项目目录的实际名称。

As a hint how I debugged this problem, I used the last compile command in sbt to see the logged debug information of the last compile ( more about logging in sbt ). 作为我如何调试此问题的提示,我使用sbt中的last compile命令来查看last compile的已记录调试信息( 有关登录sbt的更多信息 )。 From the debug info you can find out which of the sources the compiler thinks changed and which sources were invalidated by the change. 从调试信息中,您可以找到编译器认为哪些源更改以及哪些源由更改无效。 It turned out, that when using the same output directory for sbt compile and ScalaIDE, they invalidated each other every time one of the ran. 事实证明,当使用sbt compile和ScalaIDE的相同输出目录时,每次运行时它们都会相互失效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM