buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath "gradle.plugin.com.heroku.sdk:heroku-gradle:1.0.4"
        //jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
    }
}

plugins {
    id "java"
    id "maven-publish"
    id "idea"
    id "eclipse"
    id "jacoco"
    id "org.springframework.boot"
    id "com.google.cloud.tools.jib"
    id "com.gorylenko.gradle-git-properties"
    id "com.github.node-gradle.node"
    id "org.liquibase.gradle"
    id "org.sonarqube"
    id "io.spring.nohttp"
    //jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}

group = "com.adyen.demo.store"
version = "0.0.1-SNAPSHOT"

description = ""

sourceCompatibility=11
targetCompatibility=11
assert System.properties["java.specification.version"] == "1.8" || "1.9" || "10" || "11" || "12" || "13" || "14" || "15"

apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
apply from: 'gradle/heroku.gradle'
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here

if (project.hasProperty("prod") || project.hasProperty("gae")) {
    apply from: "gradle/profile_prod.gradle"
} else {
    apply from: "gradle/profile_dev.gradle"
}

if (project.hasProperty("war")) {
    apply from: "gradle/war.gradle"
}

if (project.hasProperty("gae")) {
    apply plugin: 'maven'
    apply plugin: 'org.springframework.boot.experimental.thin-launcher'
    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            mavenBom "tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}"
        }
    }
    appengineStage.dependsOn thinResolve
}


idea {
    module {
        excludeDirs += files("node_modules")
    }
}

eclipse {
    sourceSets {
        main {
            java {
                srcDirs += ["build/generated/sources/annotationProcessor/java/main"]
            }
        }
    }
}

defaultTasks "bootRun"

springBoot {
    mainClassName = "com.adyen.demo.store.StoreApp"
}

test {
    useJUnitPlatform()
    exclude "**/*IT*", "**/*IntTest*"

    testLogging {
        events 'FAILED', 'SKIPPED'
    }
    // uncomment if the tests reports are not generated
    // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
    // ignoreFailures true
    reports.html.enabled = false
}

task integrationTest(type: Test) {
    environment "ADYEN_API_KEY", "test"
    environment "ADYEN_MERCHANT_ACCOUNT", "test"
    environment "ADYEN_CLIENT_KEY", "test"
    useJUnitPlatform()
    description = "Execute integration tests."
    group = "verification"
    include "**/*IT*", "**/*IntTest*"

    testLogging {
        events 'FAILED', 'SKIPPED'
    }

    if (project.hasProperty('testcontainers')) {
        environment 'spring.profiles.active', 'testcontainers'
    }

    // uncomment if the tests reports are not generated
    // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
    // ignoreFailures true
    reports.html.enabled = false
}

check.dependsOn integrationTest
task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/tests")
    reportOn test
}

task integrationTestReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/tests")
    reportOn integrationTest
}

if (!project.hasProperty("runList")) {
    project.ext.runList = "main"
}

project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"

liquibase {
    activities {
        main {
            driver "org.h2.Driver"
            url "jdbc:h2:file:./build/h2db/db/store"
            username "store"
            password ""
            changeLogFile "src/main/resources/config/liquibase/master.xml"
            defaultSchemaName ""
            logLevel "debug"
            classpath "src/main/resources/"
        }
        diffLog {
            driver "org.h2.Driver"
            url "jdbc:h2:file:./build/h2db/db/store"
            username "store"
            password ""
            changeLogFile project.ext.diffChangelogFile
            referenceUrl "hibernate:spring:com.adyen.demo.store.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
            defaultSchemaName ""
            logLevel "debug"
            classpath "$buildDir/classes/java/main"
        }
    }

    runList = project.ext.runList
}

gitProperties {
    failOnNoGitDirectory = false
    keys = ["git.branch", "git.commit.id.abbrev", "git.commit.id.describe"]
}

checkstyle {
    toolVersion "${checkstyleVersion}"
    configFile file("checkstyle.xml")
    checkstyleTest.enabled = false
}
nohttp {
    source.include "build.gradle", "README.md"
}

configurations {
    providedRuntime
    implementation.exclude module: "spring-boot-starter-tomcat"
    all {
        resolutionStrategy {
            // Inherited version from Spring Boot can't be used because of regressions:
            // To be removed as soon as spring-boot use the same version
            force 'org.liquibase:liquibase-core:4.3.1'
        }
    }
}

repositories {
    mavenLocal()
    mavenCentral()
    //jhipster-needle-gradle-repositories - JHipster will add additional repositories
}

dependencies {
    // import JHipster dependencies BOM
    if (!project.hasProperty("gae")) {
        implementation platform("tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}")
    }

    // Use ", version: jhipsterDependenciesVersion, changing: true" if you want
    // to use a SNAPSHOT release instead of a stable release
    implementation group: "tech.jhipster", name: "jhipster-framework"
    implementation group: "com.adyen", name: "adyen-java-api-library", version: "13.0.0"
    implementation "javax.annotation:javax.annotation-api"
    implementation "org.springframework.boot:spring-boot-starter-cache"
    implementation "io.dropwizard.metrics:metrics-core"
    implementation "io.micrometer:micrometer-registry-prometheus"
    implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
    implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
    implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations"
    implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
    implementation "com.fasterxml.jackson.core:jackson-annotations"
    implementation "com.fasterxml.jackson.core:jackson-databind"
    implementation "javax.cache:cache-api"
    implementation "org.hibernate:hibernate-core"
    implementation "com.zaxxer:HikariCP"
    implementation "org.apache.commons:commons-lang3"
    implementation "javax.transaction:javax.transaction-api"
    implementation "org.ehcache:ehcache"
    implementation "org.hibernate:hibernate-jcache"
    implementation "org.hibernate:hibernate-entitymanager"
    implementation "org.hibernate.validator:hibernate-validator"
    implementation "org.liquibase:liquibase-core"
    liquibaseRuntime "org.liquibase:liquibase-core"
    liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibaseHibernate5Version}"
    liquibaseRuntime sourceSets.main.compileClasspath
    implementation "org.springframework.boot:spring-boot-loader-tools"
    implementation "org.springframework.boot:spring-boot-starter-mail"
    implementation "org.springframework.boot:spring-boot-starter-logging"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    testImplementation "org.testcontainers:mysql"
    implementation "org.springframework.boot:spring-boot-starter-security"
    implementation ("org.springframework.boot:spring-boot-starter-web") {
        exclude module: "spring-boot-starter-tomcat"
    }
    implementation "org.springframework.boot:spring-boot-starter-undertow"
    implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
    implementation "org.zalando:problem-spring-web"
    implementation "org.springframework.security:spring-security-config"

    implementation "org.springframework.security:spring-security-data"
    implementation "org.springframework.security:spring-security-web"
    implementation "io.jsonwebtoken:jjwt-api"
    if (!project.hasProperty("gae")) {
        runtimeOnly "io.jsonwebtoken:jjwt-impl"
        runtimeOnly "io.jsonwebtoken:jjwt-jackson"
    } else {
        implementation "io.jsonwebtoken:jjwt-impl"
        implementation "io.jsonwebtoken:jjwt-jackson"
    }
    implementation ("io.springfox:springfox-oas")
    implementation ("io.springfox:springfox-swagger2")
    implementation "io.springfox:springfox-bean-validators"
    implementation "mysql:mysql-connector-java"
    liquibaseRuntime "mysql:mysql-connector-java"
    implementation "org.mapstruct:mapstruct:${mapstructVersion}"
    annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
    annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernateVersion}"
    annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxbRuntimeVersion}"
    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}"
    testImplementation "org.springframework.boot:spring-boot-starter-test"
    testImplementation "org.springframework.security:spring-security-test"
    testImplementation "org.springframework.boot:spring-boot-test"
    testImplementation "com.tngtech.archunit:archunit-junit5-api:${archunitJunit5Version}"
    testRuntimeOnly "com.tngtech.archunit:archunit-junit5-engine:${archunitJunit5Version}"
    testImplementation "com.h2database:h2"
    liquibaseRuntime "com.h2database:h2"
    //jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}

if (project.hasProperty("gae")) {
    task createPom {
        def basePath = 'build/resources/main/META-INF/maven'
        doLast {
            pom {
                withXml(dependencyManagement.pomConfigurer)
            }.writeTo("${basePath}/${project.group}/${project.name}/pom.xml")
        }
    }
    bootJar.dependsOn = [createPom]
}

task cleanResources(type: Delete) {
    delete "build/resources"
}

wrapper {
    gradleVersion = "6.8.3"
}


if (project.hasProperty("nodeInstall")) {
    node {
        version = "14.16.0"
        npmVersion = "7.6.3"
        download = true
    }
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
