version: 2
defaults: &defaults
  working_directory: ~/repo
  environment:
    JVM_OPTS: -Xmx3200m
    TERM: dumb
    CI: true

defaults_gradle: &defaults_gradle
  steps:
    - checkout
    - restore_cache:
        keys:
          - gradle-dependencies-{{ checksum "build.gradle.kts" }}
          # fallback to using the latest cache if no exact match is found
          - gradle-dependencies-
    - run:
        name: Gradle Dependencies
        command: ./gradlew dependencies
    - save_cache:
        paths: ~/.m2
        key: gradle-dependencies-{{ checksum "build.gradle.kts" }}
    - run:
        name: Run All Checks
        command: ./gradlew check
    - store_artifacts:
        path: build/reports/
        destination: reports
    - store_test_results:
        path: build/reports/

jobs:
  build_gradle_jdk14:
    <<: *defaults

    docker:
      - image: openjdk:14-jdk

    <<: *defaults_gradle

  build_gradle_jdk8:
    <<: *defaults

    docker:
      - image: circleci/openjdk:8-jdk

    <<: *defaults_gradle

workflows:
  version: 2
  gradle:
        jobs:
        - build_gradle_jdk8
        - build_gradle_jdk14
