parameters:
  jdk: 1.8

steps:
- task: CacheBeta@0 #we know the very first job will have restored or created this, so this will never write built artifacts to the cache
  inputs:
    key: maven | bom/runtime/pom.xml
    path: $(Pipeline.Workspace)/.m2/repository/
    securityNamespace: cache
  displayName: Restore Maven Cache

- script: docker run --rm --publish 5432:5432 --name build-postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -d postgres:10.5
  displayName: 'start postgres'

- script: docker run --rm --publish 8000:8000 --name build-dynamodb -d amazon/dynamodb-local:1.11.477
  displayName: 'start dynamodb'

- bash: |
    sudo apt-get update &&
    sudo apt-get -y install mysql-server libmysqlclient-dev &&
    mysql -e "create user 'hibernate_orm_test'@'localhost' identified by 'hibernate_orm_test';" -uroot -proot &&
    mysql -e "create database hibernate_orm_test; grant all on hibernate_orm_test.* to 'hibernate_orm_test'@'localhost';" -uroot -proot
  displayName: 'install mysql'

- task: Maven@3
  displayName: 'Maven Build'
  inputs:
    goals: 'install'
    mavenOptions: $(MAVEN_OPTS)
    jdkVersionOption: ${{ parameters.jdk }}
    options: '-B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-mysql -Dtest-dynamodb -Dno-format'
