pipeline {
    agent any
    tools {
        maven '3.9.6'
    }
    stages {
        stage('Setup') {
            steps {
                sh "chmod +x -R ${env.WORKSPACE}"
                sh "git submodule update --init --recursive" // make sure submodules are also checked out
            }
        }
        stage ('Check Environment') {
            steps {
                sh 'mvn --version'
                sh 'java -version'
                sh 'echo $JAVA_HOME'
                sh 'echo $JAVA_INCLUDE_PATH'
            }
        }
        stage('Test') {
            steps {
                script {
                    catchError {
                        sh 'mvn test'
                    }
                }
            }
            post {
                always {
                    junit testResults: 'target/surefire-reports/*.xml', keepLongStdio: true, testDataPublishers: [[$class:'AttachmentPublisher']]
                }
            }
        }
    }
}