Why Gradle is not running dependent tasks

Viewed 19

I have the following build.gradle in an angular project:

plugins {
  id 'war'
}

task npmInstall(type:Exec)
  commandLine "npm.cmd", "install", "@angular/cli"
}

task npmBuild(type: Exec) {
   commandLine "npm.cmd", "run", "build"
}

task war.dependsOn(npmInstall, npmBuild)

but when I run the war task the npmBuild and npmInstall are not ran

1 Answers

As of Gradle 7.5, your build script doesn't compile anymore and raises the following error

> Could not create task ':task ':war''.
   > The task name 'task ':war'' must not contain any of the following characters: [/, \, :, <, >, ", ?, *, |].

The problem is with the task keyword in statement task war.dependsOn(npmInstall, npmBuild). To instruct Gradle to execute npmInstall and npmBuild before executing the war task do this:

war.configure {
  dependsOn npmInstall, npmBuild
}

You may also use war.dependsOn npmInstall, npmBuild to configure the dependency.

Related