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

    working_directory: ~/repo

    environment:
      JVM_OPTS: -Xmx3g
      TERM: dumb

    steps:
      - checkout
      - run: git submodule sync
      - run: git submodule update --init

      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "build.gradle" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: ./gradlew dependencies

      - save_cache:
          paths:
            - ~/.gradle
          key: v1-dependencies-{{ checksum "build.gradle" }}

      - run: ./gradlew check jar --max-workers=2

      - store_test_results:
          path: buildGradle/test-results

      - store_artifacts:
          path: buildGradle/libs
          destination: libs
     
      - store_artifacts:
          path: buildGradle/reports/checkstyle
          destination: checkstyle

      - store_artifacts:
          path: buildGradle/reports/spotbugs
          destination: spotbugs

      - store_artifacts:
          path: buildGradle/jacoco
          destination: jacoco
