git:
  depth: false
language: java
jobs:
  include:
    - jdk: openjdk8
    - jdk: openjdk11
      env:
        - SONAR_SKIP=true
cache:
  directories:
    - "$HOME/.m2/repository"
    - "$HOME/.npm"
    - "$HOME/.sonar/cache"
    - "$HOME/.sonar/native-sonar-scanner"
    - "$HOME/optaweb-vehicle-routing/optaweb-vehicle-routing-frontend/node"
# Download dependencies in quiet mode to avoid exceeding maximum log length.
install: >
  mvn de.qaware.maven:go-offline-maven-plugin:1.2.3:resolve-dependencies
  -DfailOnErrors -DdownloadSources=false
  -Prun-code-coverage,sonarcloud-analysis
  --quiet
before_script:
  # Fail the the build if the Red Hat package registry is referenced from package-lock.json.
  - '! grep "\"resolved\".*\.redhat\.com" optaweb-vehicle-routing-frontend/package-lock.json'
# do not install to avoid dirtying the cache
script:
  - mvn clean install -Prun-code-coverage,integration-tests --show-version
  - mvn sonar:sonar -Psonarcloud-analysis -Dsonar.skip=$SONAR_SKIP
  # check that git working tree is clean after running npm install via a frontend-maven-plugin
  # the git command returns 1 and fails the build if there are any uncommitted changes
  - git diff HEAD --exit-code
  # Sanity-check distribution assembly
  - >
    cd optaweb-vehicle-routing-distribution/target
    && unzip -q *.zip
    && cd optaweb-vehicle-routing-distribution-*/sources
    && mvn validate
