dependencies {
    developmentOnly "org.springframework.boot:spring-boot-devtools:${springBootVersion}"
    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.files("package-lock.json")
    inputs.files("build.gradle")
    inputs.dir("src/main/webapp/")

    def webpackDevFiles = fileTree("webpack/")
    webpackDevFiles.exclude("webpack.prod.js")
    inputs.files(webpackDevFiles)

    outputs.dir("build/resources/main/static/")

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

processResources {
    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
