buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url "http://repo.spring.io/plugins-release" }
        maven { url "http://repo.spring.io/milestone" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1"
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.6"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
        classpath "org.springframework.build.gradle:propdeps-plugin:0.0.7"<% if(!skipClient) {%>
        classpath "com.moowork.gradle:gradle-node-plugin:0.12"
        classpath "com.moowork.gradle:gradle-gulp-plugin:0.12"<% } %>
        classpath "se.transmode.gradle:gradle-docker:1.2"
        classpath "io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE"
        //jh-genesis-needle-gradle-buildscript-dependency - JHGenesis will add additional gradle build script plugins here
    }
}

apply plugin: 'java'
sourceCompatibility=1.<%= javaVersion %>
targetCompatibility=1.<%= javaVersion %>
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'propdeps'
<%_ if (applicationType === 'microservice' || applicationType === 'gateway' || applicationType === 'uaa') { _%>
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
  imports {
    mavenBom 'org.springframework.cloud:spring-cloud-dependencies:'+ spring_cloud_version
  }
}
<%_ } _%>
defaultTasks 'bootRun'

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

war {
    rootSpec.exclude("**/tomcat-*.jar")
}

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

bootRun {
    addResources = false
}

test {
    include '**/*UnitTest*'
    include '**/*IntTest*'

    ignoreFailures true
    reports.html.enabled = false
}

<% if (testFrameworks.indexOf('cucumber') != -1) { %>
task cucumberTest(type: Test) {
    include '**/CucumberTest*'

    ignoreFailures true
    reports.html.enabled = false
}

test.finalizedBy(cucumberTest)<% } %>

task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/tests")
    reportOn test<% if (testFrameworks.indexOf('cucumber') != -1) { %>
    reportOn cucumberTest<% } %>
}

<% if (testFrameworks.indexOf('cucumber') != -1) { %>
cucumberTest.finalizedBy(testReport)<% } %>
<% if(!skipClient) {%>
apply from: 'gradle/yeoman.gradle'<% } %>
apply from: 'gradle/sonar.gradle'
<% if (databaseType === 'sql') { %>
apply from: 'gradle/liquibase.gradle'<% } %>
<% if (testFrameworks.indexOf('gatling') != -1) { %>
apply from: 'gradle/gatling.gradle'<% } %>
apply from: 'gradle/mapstruct.gradle'
apply from: 'gradle/docker.gradle'
//jh-genesis-needle-gradle-apply-from - JHGenesis 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'
}

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

description = ''

configurations {
    providedRuntime
    <%_ if (applicationType == 'microservice' || applicationType == 'gateway' || applicationType === 'uaa') { _%>
    // netty's native is pulled by spring-cloud-starter-ribbon, but is useless unless you explicitly add the native binary dependency.
    // Having it in the classpath without the binary can cause warnings
    all*.exclude group: 'io.netty', module: 'netty-transport-native-epoll'
    <%_ } _%>
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
    maven { url 'http://repo.spring.io/milestone' }
    maven { url 'http://repo.spring.io/snapshot' }
    maven { url 'https://repository.jboss.org/nexus/content/repositories/releases' }
    maven { url 'https://oss.sonatype.org/content/repositories/releases' }
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    maven { url 'http://repo.maven.apache.org/maven2' }
}

dependencies {
    compile "io.dropwizard.metrics:metrics-core"<% if (hibernateCache == 'ehcache') { %>
    compile "io.dropwizard.metrics:metrics-annotation:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-ehcache:${dropwizard_metrics_version}"<% } %>
    compile "io.dropwizard.metrics:metrics-graphite:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-healthchecks:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-jvm:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-servlet:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-json:${dropwizard_metrics_version}"
    compile ("io.dropwizard.metrics:metrics-servlets:${dropwizard_metrics_version}") {
        exclude(module: 'metrics-healthchecks')
    }
    compile("net.logstash.logback:logstash-logback-encoder:${logstash_logback_encoder_version}") {
        exclude(module: 'ch.qos.logback')
    }
    compile "com.fasterxml.jackson.datatype:jackson-datatype-json-org:${jackson_version}"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc:${jackson_version}"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jackson_version}"<% if (databaseType == 'sql') { %>
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate4"<% } %>
    compile "com.fasterxml.jackson.core:jackson-annotations:${jackson_version}"
    compile "com.fasterxml.jackson.core:jackson-databind:${jackson_version}"
    compile ("com.ryantenney.metrics:metrics-spring:${metrics_spring_version}") {
        exclude(module: 'metrics-core')
        exclude(module: 'metrics-healthchecks')
    } <% if (hibernateCache == 'hazelcast') { %>
    compile "com.hazelcast:hazelcast:${hazelcast_version}"
    compile "com.hazelcast:hazelcast-hibernate4:${hazelcast_version}"
    compile "com.hazelcast:hazelcast-spring:${hazelcast_version}"<% } %><% if (clusteredHttpSession == 'hazelcast' && hibernateCache != 'hazelcast') { %>
    compile "com.hazelcast:hazelcast:${hazelcast_version}"<% } %><% if (clusteredHttpSession == 'hazelcast') { %>
    compile "com.hazelcast:hazelcast-wm:${hazelcast_version}"<% } %>
    <%_ if (databaseType == 'sql') { _%>
    compile "org.hibernate:hibernate-core:${hibernate_entitymanager_version}"
    compile("com.zaxxer:HikariCP:${HikariCP_version}") {
        exclude(module: 'tools')
    }
    <%_ } _%>
    <%_ if (databaseType === 'cassandra' || applicationType === 'gateway') { _%>
    compile "commons-codec:commons-codec:${commons_codec_version}"
    <%_ } _%>
    compile "commons-lang:commons-lang:${commons_lang_version}"
    compile "commons-io:commons-io:${commons_io_version}"
    compile "javax.inject:javax.inject:${javax_inject_version}"
    compile "javax.transaction:javax.transaction-api"<% if (databaseType == 'cassandra' || applicationType == 'gateway') { %>
    compile "net.jpountz.lz4:lz4:${lz4_version}"<% } %>
    compile "org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:${geronimo_javamail_1_4_mail_version}"
    <% if (hibernateCache == 'ehcache' && databaseType == 'sql') { %>
    compile ("org.hibernate:hibernate-ehcache") {
        exclude(module: 'ehcache-core')
    }<% } %><% if (databaseType == 'sql') { %>
    compile "org.hibernate:hibernate-envers"
    compile "org.hibernate:hibernate-validator"
    compile ("org.liquibase:liquibase-core:${liquibase_core_version}") {
        exclude(module: 'jetty-servlet')
    }
    compile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"<% } %>
    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-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"<% } %><% if (databaseType == 'mongodb') { %>
    compile "org.springframework.boot:spring-boot-starter-data-mongodb"<% } %>
    compile "org.springframework.boot:spring-boot-starter-security"
    compile "org.springframework.boot:spring-boot-starter-web"<% if (websocket == 'spring-websocket') { %>
    compile "org.springframework.boot:spring-boot-starter-websocket"<% } %>
    compile "org.springframework.boot:spring-boot-starter-thymeleaf"<% if (databaseType == 'cassandra' || applicationType == 'gateway') { %>
    compile("com.datastax.cassandra:cassandra-driver-core:${datastax_driver_version}") {
        exclude module: 'com.codahale.metrics'
    }
    compile "com.datastax.cassandra:cassandra-driver-extras:${datastax_driver_version}"
    compile "com.datastax.cassandra:cassandra-driver-mapping:${datastax_driver_version}"<% } %>
    <%_ if (applicationType == 'gateway') { _%>
    compile "org.springframework.cloud:spring-cloud-starter-zuul"
    <%_ } _%>
    <%_ 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-eureka"
    compile "org.springframework.cloud:spring-cloud-starter-hystrix"
    compile "org.springframework.cloud:spring-cloud-starter-spectator"
    compile "org.springframework.cloud:spring-cloud-starter-config"
    compile "org.springframework.retry:spring-retry"
    <%_ } _%>
    compile "org.springframework.cloud:spring-cloud-cloudfoundry-connector"
    compile "org.springframework.cloud:spring-cloud-spring-service-connector"
    compile "org.springframework.cloud:spring-cloud-localconfig-connector"
    compile ("org.springframework:spring-context-support") {
        exclude(module: 'quartz')
    }
    compile "org.springframework.security:spring-security-config:${spring_security_version}"
    compile "org.springframework.security:spring-security-data:${spring_security_version}"
    compile "org.springframework.security:spring-security-web:${spring_security_version}"<% if (websocket == 'spring-websocket') { %>
    compile "org.springframework.security:spring-security-messaging:${spring_security_version}" <% } %>
    <%_ if (authenticationType == 'oauth2') { _%>
    compile "org.springframework.security.oauth:spring-security-oauth2:${spring_security_oauth2_version}"
    <%_ } _%>
    <%_ if (authenticationType == 'jwt') { _%>
    compile "io.jsonwebtoken:jjwt:${jjwt_version}"
    <%_ } _%>
    <%_ if (authenticationType === 'uaa') { _%>
    compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2'
    compile group: 'org.springframework.security', name: 'spring-security-jwt'
    <%_ } _%>
    <%_ if (databaseType == 'mongodb') { _%>
    compile "com.github.mongobee:mongobee:${mongobee_version}"<% } %>
    compile("io.springfox:springfox-swagger2:${springfox_version}"){
        exclude module: 'mapstruct'
    }
    <% if (devDatabaseType == 'mysql' || prodDatabaseType == 'mysql') { %>
    compile "mysql:mysql-connector-java"<% } %><% if (devDatabaseType == 'postgresql' || prodDatabaseType == 'postgresql') { %>
    compile "org.postgresql:postgresql"<% } %><% if (devDatabaseType == 'h2Disk' || devDatabaseType == 'h2Memory') { %>
    compile "com.h2database:h2"<% } %>
    compile "fr.ippon.spark.metrics:metrics-spark-reporter:${metrics_spark_reporter_version}"
    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:${spring_social_google_version}"
    compile "org.springframework.social:spring-social-facebook"
    compile "org.springframework.social:spring-social-twitter"<% } %>
    testCompile "com.jayway.awaitility:awaitility:${awaility_version}"
    testCompile "com.jayway.jsonpath:json-path"<% if (databaseType == 'cassandra') { %>
    testCompile("org.cassandraunit:cassandra-unit-spring:${cassandra_unit_spring_version}") {
        exclude(module: 'org.slf4j')
    }<% } %><% if (testFrameworks.indexOf('cucumber') != -1) { %>
    testCompile "info.cukes:cucumber-junit:${cucumber_version}"
    testCompile "info.cukes:cucumber-spring:${cucumber_version}"<% } %>
    testCompile "org.springframework.boot:spring-boot-starter-test"
    testCompile "org.assertj:assertj-core:${assertj_core_version}"
    testCompile "junit:junit"
    testCompile "org.mockito:mockito-core"<% if (databaseType == 'sql') { %>
    testCompile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"<% } %><% if (databaseType == 'mongodb') { %>
    testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo"<% } %>
    testCompile "org.hamcrest:hamcrest-library"
    <% if (testFrameworks.indexOf('gatling') != -1) { %>
    testCompile "io.gatling.highcharts:gatling-charts-highcharts:${gatling_version}"<% } %>
    <% if (devDatabaseType != 'h2Disk' && devDatabaseType != 'h2Memory') { %>
    testCompile "com.h2database:h2"<% } %><% if (devDatabaseType == 'oracle' || prodDatabaseType == 'oracle') { %>
    runtime files('lib/oracle/ojdbc/7/ojdbc-7.jar')
    runtime fileTree(dir: 'lib', include: '*.jar')<% } %>
    optional "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
    //jh-genesis-needle-gradle-dependency - JHGenesis will add additional dependencies here
}

clean {
    delete "target"
}

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

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

task stage(dependsOn: 'bootRepackage') {
}

compileJava.dependsOn processResources
processResources.dependsOn cleanResources
