<%#
 Copyright 2013-2018 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see http://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
import org.gradle.internal.os.OperatingSystem

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        maven { url "http://repo.spring.io/plugins-release" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
        classpath "io.spring.gradle:propdeps-plugin:0.0.9.RELEASE"
        <%_ if (enableSwaggerCodegen) { _%>
        classpath "gradle.plugin.org.detoeuf:swagger-codegen-plugin:1.7.4"
        <%_ } _%>
        classpath "gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:1.4.17"
        //jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
    }
}

plugins {
    id "org.sonarqube" version "2.5"
    id "net.ltgt.apt-eclipse" version "0.13"
    id "net.ltgt.apt-idea" version "0.13"
    id "net.ltgt.apt" version "0.13"
    id "io.spring.dependency-management" version "1.0.3.RELEASE"
    <%_ if (gatlingTests) { _%>
    id "com.github.lkishalmi.gatling" version "0.7.1"
    <%_ } _%>
    <%_ if (!skipClient) { _%>
    id "com.moowork.node" version "1.2.0"
    <%_ } _%>
    //jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}

apply plugin: 'java'
sourceCompatibility=<%= JAVA_VERSION %>
targetCompatibility=<%= JAVA_VERSION %>
// Until JHipster supports JDK 9
assert System.properties['java.specification.version'] == '1.8'

apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'propdeps'
<%_ if (!skipClient) { _%>
apply plugin: 'com.moowork.node'
    <%_ if (clientFramework === 'angular1') { _%>
apply plugin: 'com.moowork.gulp'
    <%_ } _%>
<%_ } _%>
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'

dependencyManagement {
  imports {
    mavenBom 'io.github.jhipster:jhipster-dependencies:' + jhipster_dependencies_version
    //jhipster-needle-gradle-dependency-management - JHipster will add additional dependencies management here
  }
}

defaultTasks 'bootRun'

group = '<%= packageName %>'
version = '0.0.1-SNAPSHOT'

description = ''

bootRepackage {
   mainClass = '<%= packageName %>.<%= mainClass %>'
}

war {

}

springBoot {
    mainClass = '<%= packageName %>.<%= mainClass %>'
    executable = true
    buildInfo()
}

if (OperatingSystem.current().isWindows()) {
    task pathingJar(type: Jar) {
        dependsOn configurations.runtime
        appendix = 'pathing'

        doFirst {
            manifest {
                attributes 'Class-Path': configurations.runtime.files.collect {
                    it.toURI().toURL().toString().replaceFirst(/file:\/+/, '/').replaceAll(' ', '%20')
                }.join(' ')
            }
        }
    }

    bootRun {
        addResources = false
        dependsOn pathingJar
        doFirst {
            classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath)
        }
    }
} else {
    bootRun {
        addResources = false
    }
}

test {
    exclude '**/CucumberTest*'

    // 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
}

<%_ if (cucumberTests) { _%>
task cucumberTest(type: Test) {
    description = "Execute cucumber BDD tests."
    group = "verification"
    include '**/CucumberTest*'

    // 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 cucumberTest
<%_ } _%>
task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/tests")
    reportOn test
}

<%_ if (cucumberTests) { _%>
task cucumberTestReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/tests")
    reportOn cucumberTest
}
<%_ } _%>

<%_ if (!skipClient) { _%>
    <%_ if (clientFramework === 'angular1') { _%>
apply from: 'gradle/yeoman.gradle'
    <%_ } _%>
<%_ } _%>
apply from: 'gradle/docker.gradle'
apply from: 'gradle/sonar.gradle'
<%_ if (databaseType === 'sql') { _%>
apply from: 'gradle/liquibase.gradle'
<%_ } _%>
<%_ if (gatlingTests) { _%>
apply from: 'gradle/gatling.gradle'
<%_ } _%>
apply from: 'gradle/mapstruct.gradle'
<%_ if (enableSwaggerCodegen) { _%>
apply from: 'gradle/swagger.gradle'
<%_ } _%>
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here

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

if (project.hasProperty('graphite')) {
    apply from: 'gradle/graphite.gradle'
}

if (project.hasProperty('prometheus')) {
    apply from: 'gradle/prometheus.gradle'
}
<%_ if (serviceDiscoveryType || applicationType === 'gateway' || applicationType === 'microservice' || applicationType === 'uaa') { _%>

if (project.hasProperty('zipkin')) {
    apply from: 'gradle/zipkin.gradle'
}
<%_ } _%>

configurations {
    providedRuntime
    compile.exclude module: "spring-boot-starter-tomcat"
}

repositories {
    mavenLocal()
    jcenter()
    <%_ if (devDatabaseType === 'oracle' || prodDatabaseType === 'oracle') { _%>
    // more information at https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbc
    maven { url "https://maven.oracle.com" }
    <%_ } _%>
}

dependencies {
    <%_ if (cacheProvider !== 'no') { _%>
    compile "org.springframework.boot:spring-boot-starter-cache"
    <%_ } _%>
    compile "io.github.jhipster:jhipster"
    compile "io.dropwizard.metrics:metrics-core"
    <%_ if (['ehcache', 'infinispan'].includes(cacheProvider)) { _%>
    compile "io.dropwizard.metrics:metrics-jcache"
    <%_ } _%>
    compile "io.dropwizard.metrics:metrics-json"
    compile "io.dropwizard.metrics:metrics-jvm"
    compile "io.dropwizard.metrics:metrics-servlet"
    compile "io.dropwizard.metrics:metrics-servlets"
    compile "net.logstash.logback:logstash-logback-encoder"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-json-org"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
    <%_ if (databaseType === 'sql') { _%>
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
    <%_ } _%>
    compile "com.fasterxml.jackson.core:jackson-annotations"
    compile "com.fasterxml.jackson.core:jackson-databind"
    compile "com.fasterxml.jackson.module:jackson-module-afterburner"
    compile "com.ryantenney.metrics:metrics-spring"
    <%_ if (cacheProvider === 'hazelcast') { _%>
    compile "com.hazelcast:hazelcast"
    <%_ if (enableHibernateCache) { _%>
    compile "com.hazelcast:hazelcast-hibernate52"
    <%_ } _%>
    compile "com.hazelcast:hazelcast-spring"
    <%_ } _%>
    <%_ if ((applicationType === 'gateway') && cacheProvider !== 'hazelcast') { _%>
    compile "com.hazelcast:hazelcast"
    compile "com.hazelcast:hazelcast-spring"
    <%_ } _%>
    <%_ if (cacheProvider === 'infinispan') { _%>
    compile "org.hibernate:hibernate-infinispan"
    <%_ } _%>
    <%_ if (cacheProvider === 'infinispan') {_%>
    compile "org.infinispan:infinispan-spring-boot-starter"
    compile "org.infinispan:infinispan-core"
    compile "org.infinispan:infinispan-jcache"
    compile ("org.infinispan:infinispan-cloud") {
        exclude module: 'undertow-core'
    }
    <%_ } _%>
    <%_ if (['ehcache', 'hazelcast', 'infinispan'].includes(cacheProvider) || applicationType === 'gateway') { _%>
    compile "javax.cache:cache-api"
    <%_ } _%>
    <%_ if (databaseType === 'sql') { _%>
    compile "org.hibernate:hibernate-core"
    compile "com.zaxxer:HikariCP"
    <%_ } _%>
    <%_ if (databaseType === 'cassandra' || applicationType === 'gateway') { _%>
    compile "commons-codec:commons-codec"
    <%_ } _%>
    compile "org.apache.commons:commons-lang3"
    compile "commons-io:commons-io"
    compile "javax.transaction:javax.transaction-api"
    <%_ if (databaseType === 'cassandra') { _%>
    compile "org.lz4:lz4-java"
    <%_ } _%>
    <%_ if (cacheProvider === 'ehcache') { _%>
    compile "org.ehcache:ehcache"
        <%_ if (enableHibernateCache) { _%>
    compile "org.hibernate:hibernate-jcache"
        <%_ } _%>
    <%_ } _%>
    <%_ if (databaseType === 'sql') { _%>
    compile "org.hibernate:hibernate-entitymanager"
    compile "org.hibernate:hibernate-envers"
    compile "org.hibernate:hibernate-validator"
    compile "org.liquibase:liquibase-core"
    compile "com.mattbertolini:liquibase-slf4j"
    <%_ } _%>
    compile "org.springframework.boot:spring-boot-actuator"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.springframework.boot:spring-boot-loader-tools"
    compile "org.springframework.boot:spring-boot-starter-mail"
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-starter-aop"
    <%_ if (databaseType === 'sql') { _%>
    compile "org.springframework.boot:spring-boot-starter-data-jpa"
    <%_ } _%>
    <%_ if (searchEngine === 'elasticsearch') { _%>
    compile "org.springframework.boot:spring-boot-starter-data-elasticsearch"
    // needed to get around elasticsearch stacktrace about jna not found
    // https://github.com/elastic/elasticsearch/issues/13245
    compile "net.java.dev.jna:jna"
    <%_ } _%>
    <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    compile "org.springframework.boot:spring-boot-starter-data-<%=databaseType%>"
    <%_ } _%>
    <%_ if (messageBroker === 'kafka') { _%>
    compile "org.springframework.cloud:spring-cloud-stream"
    compile "org.springframework.cloud:spring-cloud-stream-binder-kafka"
    compile "org.springframework.kafka:spring-kafka"
    <%_ } _%>
    compile "org.springframework.boot:spring-boot-starter-security"
    compile ("org.springframework.boot:spring-boot-starter-web") {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile "org.springframework.boot:spring-boot-starter-undertow"
    <%_ if (websocket === 'spring-websocket') { _%>
    compile "org.springframework.boot:spring-boot-starter-websocket"
    <%_ } _%>
    compile "org.springframework.boot:spring-boot-starter-thymeleaf"
    compile "org.zalando:problem-spring-web"
    <%_ if (databaseType === 'cassandra') { _%>
    compile "com.google.guava:guava:18.0"
    compile "com.datastax.cassandra:cassandra-driver-extras"
    compile "com.datastax.cassandra:cassandra-driver-mapping"
    <%_ } _%>
    <%_ if (applicationType === 'gateway') { _%>
    compile "org.springframework.cloud:spring-cloud-starter-zuul"
    compile "com.github.vladimir-bukhtoyarov:bucket4j-core"
    compile "com.github.vladimir-bukhtoyarov:bucket4j-jcache"
    <%_ } _%>
    <%_ if (applicationType === 'microservice' || applicationType === 'gateway' || applicationType === 'uaa') { _%>
    compile "org.springframework.cloud:spring-cloud-starter"
    compile "org.springframework.cloud:spring-cloud-starter-ribbon"
    compile "org.springframework.cloud:spring-cloud-starter-hystrix"
    compile "org.springframework.cloud:spring-cloud-starter-spectator"
    compile "org.springframework.retry:spring-retry"
    <%_ } _%>
    <%_ if (serviceDiscoveryType === 'eureka') { _%>
    compile "org.springframework.cloud:spring-cloud-starter-eureka"
    compile "org.springframework.cloud:spring-cloud-starter-config"
    <%_ } _%>
    <%_ if (serviceDiscoveryType === 'consul') { _%>
    compile "org.springframework.cloud:spring-cloud-starter-consul-discovery"
    compile "org.springframework.cloud:spring-cloud-starter-consul-config"
    <%_ } _%>
    <%_ if (authenticationType === 'uaa') { _%>
    compile "org.springframework.cloud:spring-cloud-security"
    <%_ } _%>
    <%_ if (applicationType === 'microservice' || applicationType === 'gateway' || applicationType === 'uaa') { _%>
    compile "org.springframework.cloud:spring-cloud-starter-feign"
    <%_ } _%>
    compile "org.springframework.cloud:spring-cloud-spring-service-connector"
    compile "org.springframework:spring-context-support"
    compile "org.springframework.security:spring-security-config"
    compile "org.springframework.security:spring-security-data"
    compile "org.springframework.security:spring-security-web"
    <%_ if (websocket === 'spring-websocket') { _%>
    compile "org.springframework.security:spring-security-messaging"
    <%_ } _%>
    <%_ if (authenticationType === 'oauth2') { _%>
    compile "org.springframework.security.oauth:spring-security-oauth2"
        <%_ if (applicationType === 'gateway' || applicationType === 'microservice') { _%>
    compile "org.springframework.security:spring-security-jwt"
        <%_ } _%>
    <%_ } _%>
    <%_ if (authenticationType === 'jwt') { _%>
    compile "io.jsonwebtoken:jjwt"
    <%_ } _%>
    <%_ if (authenticationType === 'uaa') { _%>
    compile "org.springframework.security.oauth:spring-security-oauth2"
    compile "org.springframework.security:spring-security-jwt"
    <%_ } _%>
    <%_ if (databaseType === 'mongodb') { _%>
    compile "com.github.mongobee:mongobee"
    compile "com.google.guava:guava"
    <%_ } _%>
    <%_ if (databaseType === 'couchbase') { _%>
        compile "com.github.differentway:couchmove"
    <%_ } _%>
    compile ("io.springfox:springfox-swagger2") {
        exclude module: 'mapstruct'
    }
    compile "io.springfox:springfox-bean-validators"
    <%_ if (devDatabaseType === 'mysql' || prodDatabaseType === 'mysql') { _%>
    compile "mysql:mysql-connector-java"
    <%_ } _%>
    <%_ if (devDatabaseType === 'postgresql' || prodDatabaseType === 'postgresql') { _%>
    compile "org.postgresql:postgresql"
    <%_ } _%>
    <%_ if (devDatabaseType === 'mariadb' || prodDatabaseType === 'mariadb') { _%>
    compile "org.mariadb.jdbc:mariadb-java-client"
    <%_ } _%>
    <%_ if (devDatabaseType === 'mssql' || prodDatabaseType === 'mssql') { _%>
    compile "com.microsoft.sqlserver:mssql-jdbc"
    compile "com.github.sabomichal:liquibase-mssql"
    <%_ } _%>
    compile "org.mapstruct:mapstruct-jdk8:${mapstruct_version}"
    <%_ if (enableSocialSignIn) { _%>
    compile "org.apache.httpcomponents:httpclient"
    compile "org.springframework.social:spring-social-security"
    compile "org.springframework.social:spring-social-google"
    compile "org.springframework.social:spring-social-facebook"
    compile "org.springframework.social:spring-social-twitter"
    <%_ } _%>
    testCompile "com.jayway.jsonpath:json-path"
    <%_ if (databaseType === 'cassandra') { _%>
    testCompile ("org.cassandraunit:cassandra-unit-spring") {
        exclude(group: 'org.slf4j')
    }
    <%_ } _%>
    <%_ if (cucumberTests) { _%>
    testCompile "info.cukes:cucumber-junit"
    testCompile "info.cukes:cucumber-spring"
    <%_ } _%>
    testCompile ("org.springframework.boot:spring-boot-starter-test") {
        exclude group: 'com.vaadin.external.google', module: 'android-json'
    }
    testCompile "org.springframework.security:spring-security-test"
    testCompile "org.springframework.boot:spring-boot-test"
    testCompile "org.assertj:assertj-core"
    testCompile "junit:junit"
    testCompile "org.mockito:mockito-core"
    <%_ if (databaseType === 'sql') { _%>
    testCompile "com.mattbertolini:liquibase-slf4j"
    <%_ } _%>
    <%_ if (databaseType === 'mongodb') { _%>
    testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo"
    <%_ } _%>
    <%_ if (databaseType === 'couchbase') { _%>
    testCompile "com.github.differentway:couchbase-testcontainer"
    <%_ } _%>
    testCompile "org.hamcrest:hamcrest-library"
    <%_ if (devDatabaseType !== 'h2Disk' && devDatabaseType !== 'h2Memory') { _%>
    testCompile "com.h2database:h2"
    <%_ } _%>
    <%_ if (devDatabaseType === 'oracle' || prodDatabaseType === 'oracle') { _%>
    compile "com.oracle.jdbc:ojdbc8"
    <%_ } _%>
    <%_ if (messageBroker === 'kafka') { _%>
    testCompile "org.springframework.cloud:spring-cloud-stream-test-support"
    <%_ } _%>
    optional ("org.springframework.boot:spring-boot-configuration-processor") {
        exclude group: 'com.vaadin.external.google', module: 'android-json'
    }
    //jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}

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

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
}

task stage(dependsOn: 'bootRepackage') {
}
<%_ if (!skipClient) { _%>

if (project.hasProperty('nodeInstall')) {
    node {
        version = "${node_version}"
        npmVersion = "${npm_version}"
        yarnVersion = "${yarn_version}"
        download = true
    }
}
<%_ } _%>

compileJava.dependsOn processResources
processResources.dependsOn cleanResources,bootBuildInfo
bootBuildInfo.mustRunAfter cleanResources
