سؤال

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 (i.e. only from the command line or only from the IDE) allows project to be rebuilt incrementally. However, if I compile the project in SBT, I've notices it has to be rebuilt completely in the IDE (and vice versa). Is there any way to avoid it? If it matters, the Eclipse project is generated from SBT using sbteclipse.

هل كانت مفيدة؟

المحلول

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. 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 (e.g. to [project]/target/eclipse)
  • add to your build.sbt the following directive:

     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.

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). 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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top