Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can frontend-maven-plugin use node, npm already installed?

I am new using maven and frontend-maven-plugin. I understand that we can add this code to pom.xml to run grunt for example:

         <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- NB! Set <version> to the latest released version of    frontend-maven-plugin, like in README.md -->
            <version>@project.version@</version>

            <executions>

                <execution>
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <configuration>
                        <nodeVersion>v5.3.0</nodeVersion>
                        <npmVersion>3.3.12</npmVersion>
                    </configuration>
                </execution>

                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <!-- Optional configuration which provides for running any npm command -->
                    <configuration>
                        <arguments>install</arguments>
                    </configuration>
                </execution>

                <execution>
                    <id>npm run build</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <configuration>
                        <arguments>run build</arguments>
                    </configuration>
                </execution>

                <execution>
                    <id>grunt build</id>
                    <goals>
                        <goal>grunt</goal>
                    </goals>
                    <configuration>
                        <arguments>--no-color</arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I actually installed node and npm on my server for example: node is installed under /opt/app/trss/nodejs, npm under /opt/app/trss/nodejs/npm how can this pom.xml use the node,npm installed on my server? Thanks

like image 847
zancudo Avatar asked May 19 '16 17:05

zancudo


People also ask

What does frontend Maven plugin do?

This plugin downloads/installs Node and NPM locally for your project, runs NPM install, and then any combination of Bower, Grunt, Gulp, Jspm, Karma, or Webpack. It's supposed to work on Windows, OS X and Linux.

Do I need to install NPM after installing Node?

To publish and install packages to and from the public npm registry or a private npm registry, you must install Node. js and the npm command line interface using either a Node version manager or a Node installer. We strongly recommend using a Node version manager like nvm to install Node.

Do we need to install Node and NPM separately?

NPM is extremely useful, but, when you install it, you install it globally. It comes with Node JS, so when you install Node JS, you should have npm installed(type npm -v to see the version and whether npm is installed). "npm init" creates a package.

Can we use Maven for Node JS?

Luckily, all the popular tools were developed around a single technology, Node. js, which made it easier to integrate with other technologies, such as Maven. In this article, we will use a Maven plugin, called Frontend Maven Plugin, to integrate Gulp tasks into Maven's generate-resources phase.


2 Answers

The plugin has been designed to use a local installation of node. Using a globally installed version has been requested before but the developer's position is that node does not take up much space and will only download if missing.

Installing node locally allows developers that have not installed node globally or are using different versions to build the project without having to do anything more complicated than mvn clean install.

You can use the exec plugin run your globally installed version of npm and then grunt. Something like:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
       <execution>
          <id>run-npm-install</id>
          <phase>compile</phase>
          <goals>
             <goal>exec</goal>
          </goals>
          <configuration>
             <executable>npm</executable>
             <arguments>
                <argument>install</argument>
             </arguments>
           </configuration>
        </execution>
        <execution>
          <id>run-grunt</id>
          <phase>compile</phase>
          <goals>
             <goal>exec</goal>
          </goals>
          <configuration>
             <executable>grunt</executable>
             <arguments>
                <argument>--no-color</argument>
             </arguments>
           </configuration>
        </execution>
    </executions>
</plugin>
like image 63
Matt Champion Avatar answered Sep 18 '22 08:09

Matt Champion


Finally, it is now possible to skip node and npm installation as detailed below:

https://github.com/eirslett/frontend-maven-plugin/issues/768

<execution>
    <id>install node and npm</id>
    <goals>
        <goal>install-node-and-npm</goal>
    </goals>
    <phase>...</phase>
    <configuration>
        <skip>true</skip>
        <nodeVersion>...</nodeVersion>
        <npmVersion>...</npmVersion>
    </configuration>
</execution>
like image 30
danizen Avatar answered Sep 20 '22 08:09

danizen