Skip to content

Instantly share code, notes, and snippets.

@davegurnell
Last active April 5, 2020 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davegurnell/4a5fcca48e08e080ac613480947830f0 to your computer and use it in GitHub Desktop.
Save davegurnell/4a5fcca48e08e080ac613480947830f0 to your computer and use it in GitHub Desktop.
Minimal CircleCI 2.0 Scala build configuration with caching of Ivy/Maven dependencies
version: 2
jobs:
build:
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
- restore_cache:
key: scala-library-dependencies-{{ checksum "build.sbt" }}
- run: sbt test:compile
- save_cache:
paths: [ "~/.m2", "~/.ivy2", "~/.cache/coursier" ]
key: scala-library-dependencies-{{ checksum "build.sbt" }}
- run: sbt test
@davegurnell
Copy link
Author

Note. You may need to add this to your build.sbt to work around some weird filesystem restriction:

scalacOptions ++= Seq("-Xmax-classfile-name", "240")

See here for information: https://stackoverflow.com/questions/45022231/getting-file-name-too-long-when-running-tests-on-circleci

@lielran
Copy link

lielran commented Jul 9, 2018

what about cache of the sbt launcher itself?

@gabfssilva
Copy link

I came up with:

version: 2
jobs:
  build:
    docker:
    - image: circleci/openjdk:8-jdk
  
    working_directory: ~/repo

    environment:
      JVM_OPTS: -Xmx3200m
      TERM: dumb

    steps:
    - checkout

    - restore_cache:
        keys:
        - sbt-scala-cache-{{ checksum "build.sbt" }}

    - run: sbt clean test:compile

    - save_cache:
        paths: ["/home/circleci/.m2", "/home/circleci/.ivy2/cache", "/home/circleci/.coursier/cache", "/home/circleci/.sbt/launchers", "/home/circleci/.cache/coursier"]
        key: sbt-scala-cache-{{ checksum "build.sbt" }}

    - run: sbt test

This caches all the libs and the sbt launcher.

@ponkotuy
Copy link

ponkotuy commented Apr 23, 2019

~/.cache/coursier -> ~/.coursier/cache ?

@softdevca
Copy link

~/.cache/coursier is correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment