I have a 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 migrate it into gradle
but I can’t find examples how to do it. Grade migration tool translates only dependencies but not plugins. Is there some examples, how can I use frontend-maven-plugin
in gradle
?
Advertisement
Answer
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 with4.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