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

4

21

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

Angell answered 19/5, 2016 at 17:0 Comment(0)
S
30

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>
Skyjack answered 19/5, 2016 at 21:30 Comment(1)
Any idea, How do I specify source and target folder in this plugin. ?Betty
N
8

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>
Net answered 15/8, 2019 at 15:30 Comment(1)
this is missing a specification of the paths. just adding skip tries to use the local installation which is missingPierian
N
0

This is an older question, but it is also relevant that doing this rather than using the maven-frontend-plugin can lead to Eclipse doing the wrong thing:

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                     <lifecycleMappingMetadata>
                       <pluginExecutions>
                         <pluginExecution>
                           <pluginExecutionFilter>
                             <groupId>org.codehaus.mojo</groupId>
                             <artifactId>exec-maven-plugin</artifactId>
                             <versionRange>[1.6.0,)</versionRange>
                             <goals>
                               <goal>exec</goal>
                             </goals>
                           </pluginExecutionFilter>
                           <action>
                             <execute>
                                <runOnIncremental>true</runOnIncremental>
                             </execute>
                           </action>
                         </pluginExecution>
                       </pluginExecutions>
                     </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
Net answered 15/8, 2019 at 15:8 Comment(0)
S
0

From the thread mentioned by @Matt Champion. Here's a working example:

  1. manually download the node-v20.15.0-linux-x64.tar.gz npm-10.7.0.tgz, and place them somewhere: (note that node's tar.gz has to be placed under the nested vXX.YY.Z folder)

    home/
    └── <xxx-user>/
        └── temp/
            ├── v20.15.0/
            │   └── node-v20.15.0-linux-x64.tar.gz
            └── npm-10.7.0.tgz
    
  2. then specify the path to your downloaded files in pom.xml:

    ...
    <configuration>
        <nodeVersion>v20.15.0</nodeVersion>
        <npmVersion>10.7.0</npmVersion>
        <nodeDownloadRoot>file:///home/<xxx-user>/temp/</nodeDownloadRoot>
        <npmDownloadRoot>file:///home/<xxx-user>/temp/</npmDownloadRoot>
    </configuration>
    ...
    

That's it, should be able to mvn package normally

Schmaltz answered 24/6 at 5:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.