Port frontend-maven plugin from maven to gradle

I have com.github.eirslett:frontend-maven-plugin in my maven project.

 <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>0.0.27</version> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <phase>generate-resources</phase> </execution> <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> <phase>generate-resources</phase> <configuration> <arguments>install</arguments> </configuration> </execution> <execution> <id>bower install</id> <goals> <goal>bower</goal> </goals> <phase>generate-resources</phase> <configuration> <arguments>install</arguments> <workingDirectory>${basedir}/src/main/webapp</workingDirectory> </configuration> </execution> </executions> <configuration> <nodeVersion>v4.2.4</nodeVersion> <npmVersion>2.7.1</npmVersion> <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot> <npmDownloadRoot>https://registry.npmjs.org/npm/-/</npmDownloadRoot> <workingDirectory>${basedir}/src/main/webapp</workingDirectory> </configuration> </plugin> 

Now I need to transfer it to gradle , but I can not find examples of how to do this. The class migration tool only translates dependencies, not plugins. Are there some examples of how I can use frontend-maven-plugin in gradle ?

+10
java gradle
source share
2 answers

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

Integrate your NPM / Yarn frontend with Gradle.

Usage and configuration seem close to your Maven configuration. Define the version of Node / NPM / Yarn in the build.gradle file, link the scripts you want to run, depending on the Gradle life cycle task (clean / build / check) and that’s it. The following is a typical example of using Gradle 5.4 with NPM, taken from the documentation:

 // 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 will notice:

  • Unlike frontend-maven-plugin there is no declaration / configuration for starting the frontend assembly with Gradle, since it is already provided out of the box. Downloading, installing Node / NPM / Yarn does not require a declaration / configuration - except for version numbers, as well as build tasks. Just provide the NPM / Yarn command line to clean / build / test your interface.
  • The maximum supported version of Node should be 6.2.1 . Thus, your initial configuration from 4.2.4 will require node migration.
  • The plugin does not support Bower, and I do not think it will be supported in the future, since Bower now encourages migration to Yarn. You will find the migration guide on the Bower website.
  • The plugin does not support the use of a specific NPM release. NPM now ships with Node; the plugin uses the version built into the downloaded Node distribution.

Yours faithfully

+2
source share

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

A set of tasks that includes common interface tools and provides its binaries.

The documentation (as of March 2016) describes 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 allows you to use NodeJS-based technologies as part of your build without installing NodeJS locally on your system. It combines Gradle with NodeJS, Yarn, Grunt and Gulp.

(Edited for clarity)

Please note that this Github repo plugin is active, while the previous one has not had any commits in the last two years.

+3
source share

All Articles