image: openjdk:11-jdk-slim

variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"
  GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_CONCURRENT_ID/$CI_PROJECT_PATH/$CI_COMMIT_SHA

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle_home

stages:
  - build
  - test
  - package


cache:
  - key: "$CI_COMMIT_SHA"
    paths:
      - build
      - .gradle
  - key:
      files:
        - "*.kts"
        - "gradle.properties"
    paths:
      - .gradle_home/caches
  - key:
      files:
        - "gradle/wrapper/gradle-wrapper.properties"
    paths:
      - .gradle_home/wrapper

build:
  stage: build
  script: ./gradlew --build-cache assemble
  only:
    - master
    - merge_requests

test:
  stage: test
  script: ./gradlew check
  only:
    - master
    - merge_requests
  artifacts:
    when: always
    reports:
      junit: build/test-results/**/TEST-*.xml

package:
  stage: package
  script:
    - ./gradlew fatJar --stacktrace
  only:
    - master
  artifacts:
    paths:
      - build/libs/minosoft-fat-*.jar
    expire_in: 1 days
