Reusing SBT compilation in Travis

Basically what I want is that the Compile compiles everything (including test code, and run unit tests) and then both the next stage just picks up where the compilation left if that makes sense.

I managed to organize the build to do that but:

  • either the compilation is re-done in each step or (like restarts)
  • by caching the whole ./ the compilation is saved…but then it ignores every new change I push (obviously).

The caching config I am using comes from the sbt documentation:

cache:
  directories:
    - $HOME/.cache/coursier
    - $HOME/.ivy2/cache
    - $HOME/.sbt

Any help would be appreciated

You should try the Travis feature (in beta) that allows you to share files from one job with subsequent jobs in a build, so the flow doesn’t get disrupted. Have a look at workspaces.

It should look something like this:

jobs:
  include:
    - stage: warm_cache
      script:
        - echo "foo" > foo.txt
      workspaces:
        create:
          name: ws1
          paths:
            - foo.txt
    - stage: use_cache
      workspaces:
        use: ws1
      script:
        - cat foo.txt || true

Also, SBT 1.4 allows you to push build artifacts to a Maven server and fetch then again later, so not sure where exactly you’re having your issue at. sbt Reference Manual — Remote Caching.

Imprint