node-maven-plugin

Run NPM with maven and plug your script to maven lifecycle.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.github.mjeanroy
ArtifactId

ArtifactId

node-maven-plugin
Last Version

Last Version

0.10.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

node-maven-plugin
Run NPM with maven and plug your script to maven lifecycle.
Project URL

Project URL

https://github.com/mjeanroy/node-maven-plugin
Source Code Management

Source Code Management

https://github.com/mjeanroy/node-maven-plugin

Download node-maven-plugin

How to add to project

<plugin>
    <groupId>com.github.mjeanroy</groupId>
    <artifactId>node-maven-plugin</artifactId>
    <version>0.10.0</version>
</plugin>

Dependencies

compile (6)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.8.1
org.apache.maven : maven-settings jar 3.8.1
org.codehaus.plexus : plexus-io jar 3.2.0
org.apache.commons : commons-exec jar 1.3
com.google.code.gson : gson jar 2.8.6
com.vdurmont : semver4j jar 3.1.0

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0

test (12)

Group / Artifact Type Version
junit : junit jar 4.13.1
org.assertj : assertj-core jar 2.9.1
org.mockito : mockito-core jar 2.28.2
org.apache.commons : commons-lang3 jar 3.8.1
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0
org.apache.maven : maven-core jar 3.8.1
org.apache.maven : maven-compat jar 3.8.1
org.apache.maven : maven-model jar 3.8.1
org.apache.maven : maven-aether-provider jar 3.3.9
ch.qos.logback : logback-classic jar 1.2.3
nl.jqno.equalsverifier : equalsverifier jar 2.5.2
commons-codec : commons-codec jar 1.15

Project Modules

There are no modules declared in this project.

node-maven-plugin

Build Status

Introduction

This plugin allow you to run npm commands into your maven project.

Since version 0.2.0, this plugin can also use yarn instead of npm.

Why?

Most npm project are standards and define some classic phase:

  • Dependencies installation (npm/yarn and maybe bower dependencies).
  • Clean previous build files (using rimraf, del, etc.).
  • Linting (using tools such as jshint, eslint, csslint, etc.).
  • Tests (using karma, jest or anything else).
  • Integration tests (with protactor, webdriver.io or any other functional testing framework).
  • Building (concatenation, minification, transpilation, etc. with webpack or any other module bundler).

These steps can be easily integrated into the build lifecycle of maven:

Maven Phase Plugin goal
initialize node:install
initialize node:bower
clean node:clean
process-sources node:lint
compile node:build
test node:test
integration-test node:test-e2e
deploy node:publish

This is exactly what this plugin does!

Instruction

By default, each plugin goal is plugged into the build lifecycle (as described above). It can be used very easily:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.groupid</groupId>
  <artifactId>project-artifactid</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.mjeanroy</groupId>
        <artifactId>node-maven-plugin</artifactId>
        <version>0.2.0</version>
        <executions>
          <execution>
            <id>run-npm</id>
            <goals>
              <goal>check</goal>
              <goal>pre-clean</goal>
              <goal>install</goal>
              <goal>bower</goal>
              <goal>clean</goal>
              <goal>lint</goal>
              <goal>test</goal>
              <goal>build</goal>
              <goal>publish</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

If you want to bound each phase, here is a configuration using extensions flag:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.groupid</groupId>
  <artifactId>project-artifactid</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.mjeanroy</groupId>
        <artifactId>node-maven-plugin</artifactId>
        <version>0.2.0</version>
        <extensions>true</extensions>
        <configuration>
          <failOnMissingScript>false</failOnMissingScript>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Here is a short description of each goal:

Goal Phase
check validate Check that node and npm are available (and `yarn if enabled).
pre-clean pre-clean Run npm install (or yarn install).
install initialize Run npm install (or yarn install).
bower initialize Run npm run bower (or yarn run bower).
lint process-sources Run npm run lint (or yarn run lint).
clean clean Run npm run clean (or yarn run clean).
build compile Run npm run build (or yarn run build).
test test Run npm test (or yarn test).
test-e2e integration-test Run npm run test-e2e (or yarn run test-e2e).
publish deploy Run npm publish (or yarn publish).
start process-classes Run npm start (or yarn start).
dependencies Display npm (or yarn) dependencies.

Important: npm install (or yarn install) is run during pre-clean phase and initialize phase because each phase is bound to a different step, and there's good chances that you need to install npm dependencies before running clean script (no worry, it will run one time only during the build).

Note that each script should be defined in package.json file:

{
  "name": "project-artifactid",
  "version": "0.1.0-SNAPSHOT",
  "scripts": {
    "clean": "gulp clean",
    "bower": "bower install",
    "test": "gulp test",
    "test-e2e": "gulp test-e2e",
    "build": "gulp build",
    "start": "gulp serve"
  }
}

Options

Plugin can use these options:

Option Default
workingDirectory ${project.basedir} Directory where package.json should be available.
yarn false If set to true, yarn will be used instead of npm to install dependencies and run scripts.
node.path node Path to node executable (by default, node should be available globally)
npm.path npm Path to npm executable (by default, npm should be available globally)
yarn.path yarn Path to yarn executable (by default, yarn should be available globally)
color false If set to true (default), argument --no-color is appended to each script command.
failOnError true If set to true, build will not fail if npm command fail.
failOnMissingScript true If set to true, missing npm command will not fail the build.
ignoreProxies true If set to false , maven proxy settings will be appended to npm commands (default is true, since proxies should probably defined in .npmrc file).
addMavenArgument true If set to true , add --maven argument to each npm/yarn command

Important: Argument --maven is automatically appended to each script command (any script can check this argument to set default options on different plugins).

License

MIT License.

### Contributing

If you found a bug or you thing something is missing, feel free to contribute and submit an issue or a pull request.

Versions

Version
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0