Migrate frontend-maven-plugin from maven to gradle

Google found the Gradle Frontend Plugin for me. The plugin description simply says:

Set of tasks which wraps common frontend-tools and provide its binaries.

The documentation (as at March 2016) describes the 4 tasks (installnode, npm, grunt and gulp) and examples of their use.


An alternative (provided by @Timofei) is the Gradle Plugin for Node. The description says:

This plugin enables you to use NodeJS-based technologies as part of your build without having NodeJS installed locally on your system. It integrates Gradle with NodeJS, Yarn, Grunt, and Gulp.

(Edited for clarity)

Note that this plugin's Github repo is active while the previous one hasn't had any commits in the last two years.


You may not find any example on how to use the frontend-maven-plugin in Gradle, as it is dedicated to Maven. But you may take a look at the Siouan Frontend Gradle plugin, which is an equivalent solution for Gradle, and allows to (from official website):

Integrate your frontend NPM/Yarn build into Gradle.

The usage and configuration seems close to your Maven configuration. Define the Node/NPM/Yarn version in your build.gradle file, link the scripts you want to be run depending on the Gradle lifecycle task (clean/assemble/check), and that's all. Below is a typical usage under Gradle 5.4 with NPM, taken from the docs:

// build.gradle
plugins {
    id 'org.siouan.frontend' version '1.1.0'
}

frontend {
    nodeVersion = '10.15.3'
    // See 'scripts' section in your 'package.json file'
    cleanScript = 'run clean'
    assembleScript = 'run assemble'
    checkScript = 'run check'
}

You'll notice:

  • Contrary to the frontend-maven-plugin, there's no declaration/configuration to trigger the frontend build with Gradle, as it is already provided out of the box. The download, installation of Node/NPM/Yarn requires no declaration/configuration - except the version numbers, as well as the build tasks. Just provide the NPM/Yarn command line to clean/assemble/check your frontend.
  • The mimimum supported version of Node shall be 6.2.1. So your initial configuration with 4.2.4 will require to migrate Node.
  • The plugin does not support Bower, and I don't think it will be supported in the future, as Bower now encourages migration to Yarn. You'll find a migration guide on Bower's website.
  • The plugin does not support the use of a specific NPM release. NPM being now packaged with Node, the plugin uses the version embedded in the downloaded Node distribution.

Regards

Tags:

Java

Gradle