version: 2.1

orbs:
  sdkman: joshdholtz/sdkman@0.2.0

defaults: &defaults
  working_directory: ~/repo
  environment:
    JVM_OPTS: -Xmx3200m
    TERM: dumb
    CI_NAME: "CircleCI"

commands:
  build_and_test:
    parameters:
      reports-dir:
        type: string
        default: "build/reports/test_results"
    steps:
      - checkout
      - sdkman/setup-sdkman
      - sdkman/sdkman-install:
          candidate: kotlin
          version: 2.1.10
      - run:
          name: Download dependencies
          command: ./bld download
      - run:
          name: Compile source
          command: ./bld compile
      - run:
          name: Run tests
          command: ./bld jacoco -reports-dir=<< parameters.reports-dir >>
      - store_test_results:
          path: << parameters.reports-dir >>
      - store_artifacts:
          path: build/reports/jacoco/test/html

jobs:
  bld_jdk17:
    <<: *defaults

    docker:
      - image: cimg/openjdk:17.0

    steps:
      - build_and_test

  bld_jdk21:
    <<: *defaults

    docker:
      - image: cimg/openjdk:21.0

    steps:
      - build_and_test

workflows:
  bld:
    jobs:
      - bld_jdk17
      - bld_jdk21
