buildscript {
    repositories {
        maven { url "https://repo.grails.org/grails/core" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.4.6"
        classpath "org.grails.plugins:hibernate5:7.3.0"
        classpath "org.grails.plugins:quartz:2.0.13"
        classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
    }
}

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"org.grails.grails-web"
apply plugin:"com.bertramlabs.asset-pipeline"
apply plugin:"org.grails.grails-gsp"
apply plugin:"com.github.ManifestClasspath"

repositories {
    maven { url "https://repo.grails.org/grails/core" }
    mavenLocal()
}

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    all {
        // excluding org.apache.tomcat.embed:tomcat-embed-logging-log4j because it is not needed
        exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-logging-log4j"
    }
}

dependencies {
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    compileOnly "io.micronaut:micronaut-inject-groovy"
    console "org.grails:grails-console"
    implementation "org.springframework.boot:spring-boot-starter-logging"
    implementation 'ch.qos.logback:logback-core:1.2.13'
    implementation 'ch.qos.logback:logback-classic:1.2.13'
    //implementation "org.springframework.boot:spring-boot-starter-validation"
    implementation "org.springframework.boot:spring-boot-autoconfigure"
    implementation "org.springframework:spring-core:5.3.39"
    implementation "org.springframework:spring-beans:5.3.39"
    implementation "org.springframework:spring-context:5.3.39"
    implementation "org.springframework:spring-jdbc:5.3.39"
    implementation "org.springframework:spring-web:5.3.39"

    implementation "org.grails:grails-core"
    implementation "io.micronaut:micronaut-inject:3.10.4"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-tomcat"
    implementation "org.grails:grails-web-boot"
    implementation "org.grails:grails-logging"
    implementation "org.grails:grails-plugin-rest"
    implementation "org.grails:grails-plugin-databinding"
    implementation "org.grails:grails-plugin-i18n"
    implementation "org.grails:grails-plugin-services"
    implementation "org.grails:grails-plugin-url-mappings"
    implementation "org.grails:grails-plugin-interceptors"
    implementation "org.grails:grails-web-sitemesh:5.3.0"
    implementation "org.grails:grails-web-taglib:5.3.0"
    implementation "org.grails.plugins:cache"
    implementation "org.grails.plugins:async"
    implementation "org.grails.plugins:scaffolding"
    implementation "org.grails.plugins:events"
    implementation "org.grails.plugins:gsp"
    implementation "org.yaml:snakeyaml:1.33"
    implementation "org.apache.tomcat.embed:tomcat-embed-el:9.0.96"
    implementation "org.apache.tomcat.embed:tomcat-embed-core:9.0.96"
    // we are replacing ref. JAXB implementation with Moxy
    implementation "org.grails.plugins:hibernate5", { exclude group: 'com.sun.xml.bind', module: 'jaxb-impl' }
    implementation "org.hibernate:hibernate-core:5.6.10.Final"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:3.4.6"
    runtimeOnly "org.glassfish.web:el-impl:2.2.1-b05"
    runtimeOnly "com.h2database:h2"
    runtimeOnly "org.apache.tomcat:tomcat-jdbc:10.1.30"
    runtimeOnly "javax.xml.bind:jaxb-api:2.3.1"
    testImplementation "io.micronaut:micronaut-inject-groovy"
    testImplementation "org.grails:grails-gorm-testing-support"
    testImplementation "org.mockito:mockito-core"
    testImplementation "org.grails:grails-web-testing-support"

    implementation "org.grails.plugins:quartz:2.0.13"
    implementation 'org.quartz-scheduler:quartz:2.3.2' // gradle 5 does not pull in transitive deps
    implementation "org.grails.plugins:quartz-monitor:1.3"
    implementation "org.grails.plugins:mail:3.0.0"
    implementation "org.grails:grails-datastore-rest-client:6.1.12.RELEASE"
    runtimeOnly "org.codehaus.groovy:groovy-dateutil" // date extensions were removed in Grails 4

    implementation 'com.emc.ecs:object-client', {
        // need to exclude JAX-RS API lib as it conflicts with grails
        exclude group: 'javax.ws.rs', module: 'jsr311-api'
        // we are replacing ref. JAXB implementation with Moxy
        exclude group: 'com.sun.xml.bind', module: 'jaxb-impl'
    }
    implementation "com.emc.ecs:smart-client-ecs", {
        exclude group: 'com.sun.xml.bind', module: 'jaxb-impl'
        exclude group: 'org.slf4j', module: 'slf4j-api'
    }
    implementation "com.emc.ecs:atmos-client", { exclude group: 'javax.ws.rs', module: 'jsr311-api' }
    implementation "com.emc.ecs:mgmt-client:0.1.0", { exclude group: 'org.slf4j', module: 'slf4j-log4j12' }
    implementation platform(project(':platform'))
    implementation project(':ecs-sync-model')

    rootProject.ext.storageIncludes.each {
        implementation project(":storage-plugins:${it}-model")
    }
    rootProject.ext.filterIncludes.each {
        implementation project(":filter-plugins:${it}-model")
    }
}

bootRun {
    ignoreExitValue true
    jvmArgs(
            '-Dspring.output.ansi.enabled=always',
            '-noverify',
            '-XX:TieredStopAtLevel=1',
            '-Xmx1024m')
    sourceResources sourceSets.main
    String springProfilesActive = 'spring.profiles.active'
    systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}

// targeting Java 8
sourceCompatibility = JavaVersion.VERSION_1_8

tasks.withType(GroovyCompile) {
    configure(groovyOptions) {
        forkOptions.jvmArgs = ['-Xmx1024m']
    }
}

tasks.withType(Test) {
    useJUnitPlatform()
}

//fix for warning "Execution optimizations have been disabled for task ':ecs-sync-ui:mergeTestReports'"
tasks.named('mergeTestReports') {
    it.mustRunAfter(tasks.named('test'))
}

assets {
    minifyJs = true
    minifyCss = true
}

// fix for "CreateProcess error=206, The filename or extension is too long" when running "grailsw run-app"
grails {
    pathingJar = true
}

bootJar {
    from { rootProject.customPluginListFile }
}
