dependencies {
    developmentOnly "org.springframework.boot:spring-boot-devtools:${spring_boot_version}"
    implementation "com.h2database:h2"
}

def profiles = "dev"
if (project.hasProperty("no-liquibase")) {
    profiles += ",no-liquibase"
}
if (project.hasProperty("tls")) {
    profiles += ",tls"
}

springBoot {
    buildInfo {
        properties {
            time = null
        }
    }
}

bootRun {
    args = []
}

task webapp(type: NpmTask) {
    inputs.property('appVersion', project.version)
    inputs.files("package-lock.json")
        .withPropertyName('package-lock')
        .withPathSensitivity(PathSensitivity.RELATIVE)
    inputs.files("build.gradle")
        .withPropertyName('build.gradle')
        .withPathSensitivity(PathSensitivity.RELATIVE)
    inputs.files("angular.json")
        .withPropertyName('angular.json')
        .withPathSensitivity(PathSensitivity.RELATIVE)
    inputs.files("tsconfig.json", "tsconfig.base.json")
        .withPropertyName("tsconfig")
        .withPathSensitivity(PathSensitivity.RELATIVE)
    inputs.dir("webpack/")
        .withPropertyName("webpack/")
        .withPathSensitivity(PathSensitivity.RELATIVE)
    inputs.dir("src/main/webapp/")
        .withPropertyName("webapp-source-dir")
        .withPathSensitivity(PathSensitivity.RELATIVE)
    outputs.dir("build/resources/main/static/")
        .withPropertyName("webapp-build-dir")

    dependsOn npmInstall

    args = ["run", "webapp:build"]
    environment = [APP_VERSION: project.version]
    environment = [TYPE: project.type]
}

processResources {
    inputs.property('type', project.type)
    inputs.property('version', version)
    inputs.property('springProfiles', profiles)
    filesMatching("**/application.yml") {
        filter {
            it.replace("#project.version#", version)
        }
        filter {
            it.replace("#spring.profiles.active#", profiles)
        }
    }
}

processResources.dependsOn webapp
bootJar.dependsOn processResources
