maven npm exec-maven-plugin set registry and proxy - maven

Maven + npm install
I have following plugin to install package.json dependencies, is there a way i can run npm config set registry and npm config set proxy command with following plugin ?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>

was able to get it done through .nprmc file on project root
create file and have entry like
registry=
proxy=

Related

Conditionally run a mvn plugin if a specific directory doesn't exist

Is it possible to conditionally run a maven plugin only if a specific directory doesn't exist?
I'm essentially trying to prevent npm ci from running unnecessarily as package.json rarely changes. So ideally it would only run when node_modules doesn't exists.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>npm-install</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>ci</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
You can wrap it into a profile and activate that profile only if a given file does not exist.

Is there a way to update the version in package.json (npm version minor) in maven's pom.xml file?

I would like to update the version in package.json automatically when running a maven release. How do I update the version (npm version minor) in the pom.xml file ?
I've tried updating the pom.xml file with a plugin
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.plugin.version}</version>
<executions>
<execution>
<id>npm run version</id>
<goals>
<goal>exec</goal>
</goals>
<configurations>
<executable>cd</executable>
<arguments>
<argument>web/gui</argument>
</arguments>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>version</argument>
</arguments>
</configurations>
</execution>
<executions>
</plugin>
Nothing really happened when I ran mvn clean:release

Springboot with Maven running a react with webpack

So, I have a project with springboot that includes a maven pom file. In my pom.xml i included a front end plugin to run a npm command to start my react.js project, that uses a webpack. So when I try to deploy this app on Heroku deploy never ends, because maven run a npm run start and deploy never finishes.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<workingDirectory>web</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v4.2.1</nodeVersion>
<npmVersion>3.5.3</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run start</arguments>
</configuration>
</execution>
</executions>
</plugin>
I removed a npm run build step deploy runs good, but frontend doesn't start.
How can I fix this?
My full code is: https://github.com/ricardocunha/springboot-jwt-reactjs/
I would like to suggest something.
I think you are facing this problem because you are trying run start argument and thus the code never builds up. Probably you can try again by replacing run start with run build.

Installing node once only and not each time with Maven build

I need one help .
I am using grunt for compiling CSS/JS
I have an issue that my node package is getting created with each build and it is taking a lot of space in Jenkins . I am using maven front end plugin for the same .
I want that node package gets only created once initially and not again with each maven build .
<id>grunt</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.26</version>
<!-- optional -->
<configuration>
<workingDirectory>DIR
</workingDirectory>
<nodeVersion>v4.2.1</nodeVersion>
<npmVersion>3.5.1</npmVersion>
<installDirectory>node</installDirectory>
</configuration>
<executions>
<execution>
<id>node and npm install</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
<installDirectory>node</installDirectory>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
<installDirectory>node</installDirectory>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
We are doing a build with maven -P grunt . It is creating and installing node with each maven build .
For having node globally I am trying maven -P grunt -g , but it is not working .
In the GitHub group , I saw people mentioning we can't do with maven frontend plugin , so I tried maven exec plugin .
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-dist-npm-runtime-dependency</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>node/node</executable>
<workingDirectory>dist</workingDirectory>
<arguments>
<argument>../node/npm/cli.js</argument>
<argument>install</argument>
<argument>--production</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
But I am not able to see it working . Can anyone help how to run maven to get it working for global node installation and not installing node with each build ?
If any other suggestion to have node installed only once and not globally will be grateful .
You can't install Node or NPM globally with the Frontend maven plugin. If we take a look at the documentation we'll see that the entire purpose of the plugin is to be able to install Node and NPM in an isolated environment solely for the build and which does not affect the rest of the machine.
Node/npm will only be "installed" locally to your project. It will not
be installed globally on the whole system (and it will not interfere
with any Node/npm installations already present.)
Not meant to replace the developer version of Node - frontend
developers will still install Node on their laptops, but backend
developers can run a clean build without even installing Node on their
computer.
Not meant to install Node for production uses. The Node usage is
intended as part of a frontend build, running common javascript tasks
such as minification, obfuscation, compression, packaging, testing
etc.
You can try to run the plugin with two different profiles, one for install and one for day-to-day use after installation. In the below example, you should be able to install Node and NPM by running:
mvn clean install -PinstallNode
Then every build after:
mvn clean install -PnormalBuild
Or because normalBuild is set to active by default, just:
mvn clean install
Notice install goals are not in the day-to-day profile:
<profiles>
<profile>
<id>installNode</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.26</version>
<!-- optional -->
<configuration>
<workingDirectory>DIR</workingDirectory>
<nodeVersion>v4.2.1</nodeVersion>
<npmVersion>3.5.1</npmVersion>
<installDirectory>node</installDirectory>
</configuration>
<executions>
<execution>
<id>node and npm install</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
<installDirectory>node</installDirectory>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
<installDirectory>node</installDirectory>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>normalBuild</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.26</version>
<!-- optional -->
<configuration>
<workingDirectory>DIR</workingDirectory>
<nodeVersion>v4.2.1</nodeVersion>
<npmVersion>3.5.1</npmVersion>
<installDirectory>node</installDirectory>
</configuration>
<executions>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Install grunt using maven

I am stuck with using maven for build and compile , but now introducing JavaScript building and automation has provided an interesting challenge, that can we use maven to install Grunt?
I have searched and found a lot of pom.xml examples ,example running grunt and yoeman, etc but NONE for installing grunt
something like:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>Install Grunt</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>grunt</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Sorry, this is a very late answer... by using the frontend maven plugin you "install" Grunt by putting it in package.json. Then, npm will download it for you. (Like in the example project)

Resources