# How to cache SBT incremental compilation

**URL:** <https://discuss.circleci.com/t/how-to-cache-sbt-incremental-compilation/18746>\
**Category:** Build Environment\
**Tags:** caching, cache, sbt, scala, circle-yml\
**Created:** [December 13, 2017, 12:36am UTC](https://discuss.circleci.com/t/how-to-cache-sbt-incremental-compilation/18746 "2017-12-13T00:36:26Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![hannahlaura44](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/hannahlaura44/32/12134_2.png) [@hannahlaura44](https://discuss.circleci.com/u/hannahlaura44)\
**Post date:** [December 13, 2017, 12:36am UTC](https://discuss.circleci.com/t/how-to-cache-sbt-incremental-compilation/18746/1 "2017-12-13T00:36:26Z")

</div>

I am working to reduce the compile time for my build. Locally, SBT caches incremental compilations so that only files that are changed are re-compiled between builds. On circle ci, however, every build compiles all my source code, which takes 5 minutes.

I’ve tried adding this to my circle.yml, to no avail:

```
dependencies:
  cache_directories:
    - "~/.iv2"
    - "~/.sbt"
    - "target"
    - "project/target"

```

I get this error:

```
    sbt.InvalidScalaInstance: Scala instance doesn't exist or is invalid: 
    version 2.11.8, library jar: /home/ubuntu/my_project/lib_managed/jars/org.scala-lang/scala-library/scala-library-2.11.8.jar, compiler jar: /home/ubuntu/my_project/lib_managed/jars/org.scala-lang/scala-compiler/scala-compiler-2.11.8.jar

```

Has anyone been able to successfully cache incremental compilation from sbt so that on the next build only re-compiles the modified files?

------------------------------------------------SOLUTION----------------------------------------------------------------------------------

I added this to circle.yml and it worked. Reduced my compile time to 44s.

```
dependencies:
  cache_directories:
    - "~/.iv2"
    - "~/.sbt"
    - "lib_managed" #### <-- need this
    - "target"
    - "project/target"
```

---

_[View the full topic](https://discuss.circleci.com/t/how-to-cache-sbt-incremental-compilation/18746)._
