How to synchronize Intellij and sbt assemblies for scala project

I have an sbt project that I imported into Intellij. Sometimes I build a project on the command line using sbt, and then when I need to debug, I build it from Intellij. However, every time I alternate it, a complete overhaul is required when there is no need. Both build methods are output to the same class folder, namely ... / target / scala -2.11 / classes, so I don’t understand why a complete rebuild occurs?

+6
source share
2 answers

IntelliJ IDEA cannot reuse classes created by other build systems because it has its own incremental compiler that tracks dependencies and creates caches at compile time so that it can only compile changed and dependent files when you make changes to the code. When you built using SBT / Maven / Gradle or the javac command line, the IntelliJ IDEA compiler cache does not know what has changed and what files it should compile, so it performs a complete rebuild.

The solution is to use different output directories for the IDE and SBT, so IntelliJ IDEA will only rebuild files that have changed since the last build in the IDE, and your build of the SBT for the command line will not result in rebuild in the IDE.

sbt-ide-settings .

plugins.sbt ( , ):

resolvers += Resolver.url("jetbrains-bintray",url("http://dl.bintray.com/jetbrains/sbt-plugins/"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.jetbrains" % "sbt-ide-settings" % "0.1.2")

IDE build.sbt:

ideOutputDirectory in Compile := Some(new File("target/idea/classes"))
ideOutputDirectory in Test := Some(new File("target/idea/test-classes"))

.

+3

CrazyCoder, intellij sbt build . , , , .

CrazyCoder , , sbt . , Intellij sbt , sbt . .

:

file
  > Settings
    > Build, Execution, Deployment
      > Build Tools
        > SBT 
          > Use SBT shell for build and import

, , intellij 2017.2.3, , , SBT.

. jetbrains: https://youtrack.jetbrains.com/issue/SCL-10984

+3

All Articles