plugins {
    id "java"
    id "war"
    id "org.springframework.boot" version "2.1.4.RELEASE"
    id "io.spring.dependency-management" version "1.0.7.RELEASE"
    id "com.moowork.node" version "1.2.0"
}

final def jUnitVersion = '5.1.0'
final def sparkVersion = '2.4.3'
final def hadoopVersion = '3.2.0'
final def awsSdkVersion = '1.11.563'
final def nodeVersion = '10.16.0'
final def currentNpmVersion = '6.9.0'

repositories {
    jcenter()
    mavenCentral()
}

sourceCompatibility = 1.8

allprojects {
    group = 'com.infoclinika'
    version = '1.0'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-log4j2')
    compile('org.springframework.boot:spring-boot-starter-web')

    compile group: 'com.google.guava', name: 'guava', version: '27.1-jre'

    compile group: 'org.apache.spark', name: 'spark-core_2.12', version: sparkVersion
    compile group: 'org.apache.spark', name: 'spark-sql_2.12', version: sparkVersion

    compile group: 'org.apache.hadoop', name: 'hadoop-common', version: hadoopVersion
    compile group: 'org.apache.hadoop', name: 'hadoop-client', version: hadoopVersion
    compile group: 'org.apache.parquet', name: 'parquet-hadoop', version: '1.10.1'

    compile group: 'com.amazonaws', name: 'aws-java-sdk-core', version: awsSdkVersion
    compile group: 'com.amazonaws', name: 'aws-java-sdk-athena', version: awsSdkVersion
    compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: awsSdkVersion

    testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'junit'
    }

    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
    testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
    testRuntime group: 'org.mockito', name: 'mockito-core', version: '2.+'
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
}

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

sourceSets {
    main {
        resources {
            exclude '/ui/e2e/'
            exclude '/ui/node_modules/'
            exclude '/ui/src/'
            exclude '**/ui/*.*'
        }
    }
}

node {
    version = nodeVersion
    npmVersion = currentNpmVersion
    download = true
    nodeModulesDir = file("${project.projectDir}/src/main/resources/ui")
}

task buildUi(type: NpmTask) {
    args = ['run', 'build-prod']
}

buildUi.dependsOn(npm_install)
bootWar.dependsOn(buildUi)

test {
    useJUnitPlatform()

    testLogging {
        events "passed", "skipped", "failed"
    }
}
