How to script in build.gradle file

I am a beginner with Gradle. The script provided is my build.gradle file. Can someone please assist me in correcting it?

plugins {
    id 'java'

task npmInstallAngularCLI(type: Exec) {
    workingDir '/home/indiran/Music/Test-2/Client/devenv'
    commandLine 'npm', 'install', '@angular/cli', '-f'

task buildProject(type: Exec) {
    workingDir '/home/indiran/Music/Test-2/Client/devenv'
    commandLine 'ng', 'build', '--prod'

// Define default tasks to execute when running 'gradle' command
defaultTasks 'buildProject'

What problem do you have with it?

Besides some general things:

  • Better use Kotlin DSL than Groovy DSL, by now it is the default DSL, you immediately get type-safe build scripts, actually useful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio
  • Is it really a Java project, or why do you apply the java plugin?
  • If you ever consider sharing or even just moving the project, don’t use absolute paths
  • There is a dedicated Node.js plugin, that even provisions Node.js for you if you care. From what you showed, you just use Gradle as replacement for a shell script. You can do that, but you might miss out on some things. :smiley: