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

 This file is part of the JHipster project, see https://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

      https://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.
-%>
<%_ if (devDatabaseType !== prodDatabaseType && (prodDatabaseTypeMariadb || prodDatabaseTypeMssql || prodDatabaseTypeMysql || prodDatabaseTypePostgresql)) { _%>
sourceSets {
    test {
        java {
            exclude '<%= packageFolder %>/config/<% if (prodDatabaseTypeMariadb) { %>Mariadb<% } else if (prodDatabaseTypeMssql) { %>MsSql<% } else if (prodDatabaseTypeMysql) { %>Mysql<% } else if (prodDatabaseTypePostgresql) { %>PostgreSql<% } %>TestContainer.java'
        }
    }
}

<%_ } _%>
dependencies {
    developmentOnly "org.springframework.boot:spring-boot-devtools"
    // jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}

ext {
    springProfiles = "dev" + springProfiles
}

springBoot {
    buildInfo {
        excludes = ['time']
    }
}

bootRun {
    args = ["--spring.profiles.active=${springProfiles}"]
<%_ if (cacheProviderInfinispan) { _%>
    jvmArgs = ["-Djgroups.tcp.address=NON_LOOPBACK", "-Djava.net.preferIPv4Stack=true"]
<%_ } _%>
}

<%_ if (!skipClient) { _%>
task webapp(type: NpmTask) {
    inputs.property('appVersion', project.version)
    inputs.files("build.gradle")
        .withPropertyName('build.gradle')
        .withPathSensitivity(PathSensitivity.RELATIVE)
    inputs.files(<%- javaNodeBuildPaths.filter(file => !file.endsWith('/')).map(file => `'${file}'`).join(', ') %>)
        .withPropertyName('<%= clientFramework %>-build')
        .withPathSensitivity(PathSensitivity.RELATIVE)
    <%_ for (const file of javaNodeBuildPaths.filter(file => file.endsWith('/'))) { _%>
    inputs.dir("<%= file %>")
        .withPropertyName("<%= file %>")
        .withPathSensitivity(PathSensitivity.RELATIVE)
    <%_ } _%>

    outputs.dir("<%= clientDistDir %>")
        .withPropertyName("webapp-build-dir")

    dependsOn npmInstall

    args = ["run", "webapp:build"]
    environment = [APP_VERSION: project.version]
}
<%_ } _%>

processResources {
    inputs.property('version', version)
    inputs.property('springProfiles', springProfiles)
    filesMatching("**/application.yml") {
        filter {
            it.replace("@project.version@", version)
        }
<%_ if (!serviceDiscoveryAny) { _%>
        filter {
            it.replace("@spring.profiles.active@", springProfiles)
        }
<%_ } _%>
    }
<%_ if (serviceDiscoveryEureka || serviceDiscoveryConsul) { _%>
    filesMatching("**/bootstrap.yml") {
        filter {
            it.replace("@spring.profiles.active@", springProfiles)
        }
    }
<%_ } _%>
}

task integrationTest(type: Test) {
    maxHeapSize = "1G"
    useJUnitPlatform()
    description = "Execute integration tests."
    group = "verification"
    include "**/*IT*", "**/*IntTest*"
<%_ if (cucumberTests) { _%>
    exclude "**/*CucumberIT*"
<%_ } _%>
    testLogging {
        events 'FAILED', 'SKIPPED'
        exceptionFormat "full"
    }
    systemProperty('spring.profiles.active', 'test,testdev')
    systemProperty('java.security.egd', 'file:/dev/./urandom')
    // 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.required = false
<%_ if (reactive) { _%>
    if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
        jvmArgs += [
            "-XX:+AllowRedefinitionToAddDeleteMethods"
        ]
    }
<%_ } _%>
}
integrationTest.dependsOn test

<%_ if (!skipClient) { _%>
processResources.dependsOn webapp
bootJar.dependsOn processResources
<%_ } _%>
