Introducing the NPM Maven Plugin

September 25 2013

2 comments 0
motif

Introduction

Suppose that you have a Maven project and you want to download Node.js modules previously uploaded to NPM. One way of doing that without running is by using the npm-maven-plugin. It allows the user to download the required Node modules without running node.js: It is completely implemented on the JVM.

Getting Started

First of all you will need to add the Mule Maven repo to you pom.xml file:

After doing that, you will need to add the following to the build->plugin section of your pom.xml file:

Then just execute:

mvn generate-sources

and that’s it!

One more thing…

By default, the modules can be found in src/main/resources/META-INF but that path can be changed setting the ‘outputDirectory’ parameter.

Also, module transitivity is taken into account. That means that it will download all the required dependencies before downloading the specified module.

Show me the code!

The source code can be found here. Feel free to fork the project and propose changes to it.

Happy (Node.js and Maven) hacking!

Update: Another interesting approach of achieving the same (but actually running node) can be done using the Frontend Maven Plugin.


We'd love to hear your opinion on this post

2 Responses to “Introducing the NPM Maven Plugin”

  1. This sounds like a great plugin. Too bad we’re using Gradle: any chance you could port it to a Gradle-plugin as well?

    Cheers!

    Agree(0)Disagree(0)Comment
  2. Hi Jeroen,

    Thanks for the interest. Currently, I’m working on other projects but feel free if you want to submit a pull request in order to provide Gradle-plugin bindings. It should be pretty simple as the NPM code is decoupled from Maven.

    Cheers,

    Agree(0)Disagree(0)Comment