Gradle: run task only if folder exists

Viewed 292

I've a Java application which has a web component. I am trying to skip running of npm install if the node_modules folder already exists:

tasks.register<NpmTask>("appNpmInstall") {
    onlyIf { !file("node_modules").exists() }
    description = "Installs all dependencies from package.json"
    workingDir = file("${project.projectDir}/src/main/webapp")
    args = listOf("install")
}

However, with this configuration, the task still runs. How do I skip the task if node_modules exists?

0 Answers
Related