How to re-use compiled sources in different machines

While https://stackoverflow.com/a/37440714/8261 pointed at the right direction, the underlying issue and the solution for this was different.

Issue

SBT seems to recompile everything when it's run on different stages of a docker build. This is because docker compresses images created in each stage, which strips out the millisecond portion of the lastModifiedDate from sources.

SBT depends on lastModifiedDate when determining if sources have changed, and since its different (the milliseconds part) the build triggers a full recompilation.

Solution

  • Java 8: Setting -Dsbt.io.jdktimestamps=true when running SBT as recommended in https://github.com/sbt/sbt/issues/4168#issuecomment-417655678 to workaround this issue.

  • Newer: Follow recomendation in https://github.com/sbt/sbt/issues/4168#issuecomment-417658294

I solved the issue by setting SBT_OPTS env variable in the docker file like

ENV SBT_OPTS="${SBT_OPTS} -Dsbt.io.jdktimestamps=true"

The test project has been updated with this workaround.

Tags:

Scala

Sbt