Plugin com.moowork.node was not found error

In this blog post, I would like to add about few errors which I came across while using Gradle. Details explanation of Gradle and its working is not scoped in this post so I will go directly to the error message and fix for it.

Below is my Gradle build file.

Code

plugins {
  id "com.moowork.node" version "3.5.1"
}

node {
  download = true
}

task build

build.dependsOn npm_build
npm_build.dependsOn npmInstall

When I try to execute the build command, the following errors were generated.

Error.1

$ ./gradlew build

FAILURE: Build failed with an exception.

* Where:
Build file '/home/cicd/build.gradle' line: 8

* What went wrong:
Plugin [id: 'com.moowork.node', version: '3.5.1'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.moowork.node:com.moowork.node.gradle.plugin:3.5.1')
  Searched in the following repositories:
    Gradle Central Plugin Repository

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

Explanation

The reason for the above error is that I am using a node plugin named “com.moowork.node” which is outdated or not maintained by the author. An alternative to this plugin is “com.github.node-gradle.node“. Using this plugin and a supported version will fix the issue. The updated build file is given below.

Resolution

plugins {
  id "com.github.node-gradle.node" version "3.5.1"
}

node {
  download = true
}

task build

build.dependsOn npm_build
npm_build.dependsOn npmInstall

I made the modification to my build file and triggered the build command again but still failed with the following error.

Error.2

$ ./gradlew build

> Task :npm_build FAILED
Unknown command: "build"

To see a list of supported npm commands, run:
  npm help

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':npm_build'.
> Process 'command '/home/cicd/.gradle/nodejs/node-v16.14.2-darwin-x64/bin/npm'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
3 actionable tasks: 2 executed, 1 up-to-date

Explanation

My build failed again because I didn’t use the correct version of the node.

Resolution

plugins {
  id "com.github.node-gradle.node" version "3.5.1"
}

node {
  download = true
  version = "12.18.2"
}

task build

build.dependsOn npm_build
npm_build.dependsOn npmInstall

Result

$ ./gradlew build

BUILD SUCCESSFUL in 7s
3 actionable tasks: 2 executed, 1 up-to-date

Leave a Reply

Your email address will not be published. Required fields are marked *