javascriptnode.jsmavennpmgruntjs

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


Solution

  • 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>