Build the frontend-maven-plugin project
masterTo build the plugin project itself from the source, run the standard Maven clean install command.
$ mvn clean installrepository·master·Indexed 26 days ago
https://github.com/eirslett/frontend-maven-pluginA Maven plugin that automates the management of frontend build tools by downloading and installing local versions of Node, NPM, Yarn, Corepack, or Bun. It allows developers to run frontend tasks such as Webpack, Gulp, Grunt, and Karma tests without requiring global installations on their machines, ensuring consistent build environments across different systems.
To build the plugin project itself from the source, run the standard Maven clean install command.
$ mvn clean installThe plugin includes M2E support, including lifecycle mappings and support for incremental builds in Eclipse.
To optimize build times:
install-node-and-npm goal only runs during a full project build.npm goal only runs during an incremental build if the package.json file has changed.grunt and gulp goals, you can use the srcdir and triggerfiles configuration options to check for changes in specific source files before execution.To use Yarn as your package manager, use the install-node-and-yarn goal.
Yarn Berry (2.x+) Support: If your project uses Yarn Berry, the plugin detects a .yarnrc.yml file and automatically installs the version specified in yarnVersion as a 'bootstrap' 1.x version before handing over to your project-specific version.
<plugin>
<executions>
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v24.12.0</nodeVersion>
<yarnVersion>v0.16.1</yarnVersion>
<nodeDownloadRoot>http://myproxy.example.org/nodejs/</nodeDownloadRoot>
<yarnDownloadRoot>http://myproxy.example.org/yarn/</yarnDownloadRoot>
</configuration>
</plugin>To use this plugin, add it as a dependency in your Maven pom.xml. This plugin allows you to manage Node and NPM locally within your project, ensuring consistent build environments across different machines without requiring global installations.
Note: This plugin is designed to download and install Node/NPM locally. It does not support using Node or NPM versions that are already installed on your system. If you need to use an existing installation, use exec-maven-plugin instead.
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version:
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>LATEST_VERSION</version>
...
</plugin>
</plugins>To install Node.js and npm locally within your project (without affecting the global system), use the install-node-and-npm goal. The versions are downloaded from https://nodejs.org/dist and extracted into a node folder in your installation directory.
Note: You should add the node folder to your .gitignore.
<plugin>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v24.12.0</nodeVersion>
<npmVersion>11.6.2</npmVersion>
<downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>
</configuration>
</plugin>Use the install-node-and-corepack goal to let Corepack manage your package manager versions. Node is downloaded from https://nodejs.org/dist. Corepack is either provided with Node or downloaded from https://repository.npmjs.org.
<plugin>
<executions>
<execution>
<id>install-node-and-corepack</id>
<goals>
<goal>install-node-and-corepack</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v24.12.0</nodeVersion>
<corepackVersion>v0.25.2</corepackVersion>
<nodeDownloadRoot>http://myproxy.example.org/nodejs/</nodeDownloadRoot>
<corepackDownloadRoot>http://myproxy.example.org/corepack/</corepackDownloadRoot>
</configuration>
</plugin>To install Bun, use the install-bun goal. Bun is downloaded from https://github.com/oven-sh/bun/releases/download/ and extracted into a bun folder in your installation directory.
<plugin>
<executions>
<execution>
<id>install bun</id>
<goals>
<goal>install-bun</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<bunVersion>v1.1.34</bunVersion>
<bunDownloadRoot>http://myproxy.example.org/bun/</bunDownloadRoot>
</configuration>
</plugin>Set the directory where package.json and frontend config files (like Gruntfile.js) reside. Defaults to the project base directory.
Set the folder where Node/npm/Yarn/etc. are installed. This can be set globally for the plugin or per goal.
<configuration>
<workingDirectory>src/main/frontend</workingDirectory>
<installDirectory>target</installDirectory>
</configuration>To use a private npm registry with Yarn, you can use the npmRegistryURL configuration option within a yarn execution.
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>install</arguments>
<npmRegistryURL>http://myregistry.example.org/</npmRegistryURL>
</configuration>
</execution>Use the environmentVariables configuration key to pass custom variables to the frontend processes.
<configuration>
<environmentVariables>
<Jon>Snow</Jon>
<NODE_ENV>${NODE_ENV}</NODE_ENV>
</environmentVariables>
</configuration>The plugin automatically inherits proxy settings from Maven's settings.xml. If you need to disable this inheritance for specific tools, use the following configuration keys:
npmInheritsProxyConfigFromMaven: Set to false to stop npm from using Maven proxy settings.bowerInheritsProxyConfigFromMaven: Set to false to stop bower from using Maven proxy settings.yarnInheritsProxyConfigFromMaven: Set to false to stop yarn from using Maven proxy settings.<configuration>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
<bowerInheritsProxyConfigFromMaven>false</bowerInheritsProxyConfigFromMaven>
<yarnInheritsProxyConfigFromMaven>false</yarnInheritsProxyConfigFromMaven>
</configuration>Use the karma goal to run JavaScript tests. You can specify a custom configuration file using karmaConfPath.
CI Best Practices: It is recommended to use a separate configuration (e.g., karma.conf.ci.js) for CI environments that generates XML reports and code coverage.
Maven Flags:
-DskipTests: Skips Karma tests.-Dmaven.test.failure.ignore: Allows the build to continue even if tests fail (useful for CI).<execution>
<id>javascript tests</id>
<goals>
<goal>karma</goal>
</goals>
<phase>test</phase>
<configuration>
<karmaConfPath>src/test/javascript/karma.conf.ci.js</karmaConfPath>
</configuration>
</execution>