I am trying to deploy my web-app to heroku. To run my app i need to execute
npm run build
So i need to install npm to Heroku. I found maven plugins which does it.And a plugin which executes a script.
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version:
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>1.7.5</version>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v11.15.0</nodeVersion>
<npmDownloadRoot>https://nodejs.org/dist/v6.11.3/win-x64/node.exe</npmDownloadRoot>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>npm run build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
But when i try to push it to heroku I get this:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (npm run build) on project vstup: Command execution failed. Cannot run program "npm" (in directory "/tmp/build_6883506630fbb2f73ce1bcb9a5d6cf3d"): error=2, No such file or directory -> [Help 1]
I had a same error today with GitLab-ci and the spring-boot app.
I had to run before script to install the missing npm:
before_script:
- 'apt-get update'
- 'apt-get install -y npm'
script:
- 'mvn deploy'
This will install npm before running the maven exec plugin with the npm executable.
My mvn plugin configuration was:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<workingDirectory>${project.basedir}/src/main/frontend</workingDirectory>
</configuration>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Hint:
maybe you can try to use after_script and before_script to run ls -Ra and see if a file or directory is missing, but it wasn't my case
My POM file has plugins that build the front end builds. However, when we run mvn clean install it runs the front end grunt/npm exec twice. How do I avoid multiple executions?
All help is appreciated. Since the grunt build takes time, removing the duplicate runs will shorten the build time.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>src/main/raw_ui</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-bower-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>bower</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>src/main/raw_ui</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-grunt</id>
<phase>generate-sources</phase>
<configuration>
<executable>grunt</executable>
<arguments>
<argument>build</argument>
<argument>-f</argument>
</arguments>
<workingDirectory>src/main/raw_ui</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
I don't really know why this solves the problem, but after changing the phase from 'generate-sources' to 'process-classes' did the thing, it now runs only once.
I've found here: Maven plugin executes multiple times during build that certain goals can execute certain lifecycles, that's why I tried changing the phase to run node scripts.
Its posibble to just execute gulp,grunt,npm,bower task without install node and npm through the plugin using the node and npm installed in the system?
<build>
<plugins>
<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>v0.12.2</nodeVersion>
<npmVersion>2.7.6</npmVersion>
</configuration>
</execution>-->
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>--no-color</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Doesn't look like it, according to the author's comments on this issue :
https://github.com/eirslett/frontend-maven-plugin/issues/277
Maven-exec-plugin may have what you need.
I have a project using Maven and the frontend-maven-plugin (com.github.eirslett).
As I run mvn install all the executions from the plugin run, and they create a node_modules, bower_components, and node folders in the src/main/webapp root, where the actual frontend code is.
The thing is, I wanted to mvn install only execute and create those in war the package generated in the build directory, not in the versioned application code, just like it does with Java libraries.
Is there a way to achieve that?
This is the relevant part of my pom.xml:
<build>
<directory>build</directory>
<outputDirectory>build/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>WEB-INF/weblogic.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
...
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.20</version>
<configuration>
<workingDirectory>src/main/webapp</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v0.10.34</nodeVersion>
<npmVersion>2.1.11</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
It's possible to use <installDirectory> configuration parameter to choose where to install NodeJS.
frontend-maven-plugin will install node_modules in the place where it founds package.json. That's why you need to provide copy of your web resources with package.json to some target/<sub-path>.
Then frontend-maven-plugin may be configured by this way:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.24</version>
<configuration>
<nodeVersion>v0.11.14</nodeVersion>
<npmVersion>2.13.4</npmVersion>
<installDirectory>target/<sub-path></installDirectory>
<workingDirectory>target/<sub-path></workingDirectory>
</configuration>
...
The plugin (frontend-maven-plugin) mostly supports this. The "workingDirectory" parameter tells plugin where to do the work (i.e. npm install). That requires though that the build files (i.e. package.json, gruntFile.js) be in that workingDirectory. To accomodate this I added a antrun execution to copy those files over (with filtering) before the rest of the build. My grunt file then references the files from source when appropriate and any output goes in my target-grunt folder.
Here is my config:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.20</version>
<configuration>
<workingDirectory>target-grunt</workingDirectory>
</configuration>
<executions>
...
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>prepare-grunt</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- copy, filter, rename -->
<filter token="moduleName" value="${moduleName}" />
<filter token="project.version" value="${project.version}" />
<filter token="project.artifactId" value="${project.artifactId}" />
<copy file="${basedir}/target-grunt/imported-js/main/js/com/verisk/underwriting/config/grunt/npm-package-module/0.0.1/npm-package-module-0.0.1.js" tofile="${basedir}/target-grunt/package.json" filtering="true" failonerror="true" verbose="true" />
<copy file="${basedir}/Gruntfile.js" tofile="${basedir}/target-grunt/Gruntfile.js" failonerror="true" verbose="true" />
</target>
</configuration>
</execution>
</executions>
</plugin>
A possible way in order to do not dirty the frontend resources dir, contained as example in src/main/frontendResources, coming from GIT (or another source repo) with the node_modules, bower_components, ..., directories and files generated during npm, bower and grunt execution is:
using maven-resources-plugin, copy the sources directory src/main/frontendResources
in /target/webappStagingDir subfolder during
initialization phase
set the workingDirectory and
installDirectory in frontend-maven-plugin to /target/webappStagingDir
set the bower output directory as
subfolder of /target/webappStagingDir. In example put
{"directory":
"bower_components"}
in .bowerrc file
after bower build, using
maven-resources-plugin, copy the output built sources contained in
bower_components folder to /target/${artifactId}-${version} during
prepare-package phase (before war building)
Here is the pom slice:
...
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>${basedir}/target/frontendResourcesStagingDir</workingDirectory>
<installDirectory>${basedir}/target/frontendResourcesStagingDir</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v8.12.0</nodeVersion>
<npmVersion>6.4.1</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<phase>generate-resources</phase>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<phase>generate-resources</phase>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<!--
Copy of the /frontendResources directory, coming from GIT, in /target directory
executed before the compiling and build of frontend resources
That dir will be the working directory of npm, bower, grunt
in order to avoid the creation of the direcotries node, node_modules, bower_components, ...
(they may be committed in repository)
-->
<execution>
<id>copy-frontendResources-toStagingDir-beforeBuild</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/frontendResourcesStagingDir</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/frontendResources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<!--
Copy of the /frontendResourcesStagingDir/grunt_output directory in /target/ directory
executed after build of frontend resources and before the war pachage creation
it contains the output of grunt install execution
-->
<execution>
<id>copy-frontendResources-afterBuild</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/${artifactId}-${version}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/frontendResourcesStagingDir/grunt_output</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
...
This solution is useful also for mixed projects with frontend in Node.js and backend in Java that has a single .war file as output deliverable
I am trying to run Sonar build on Jenkins. My project contains both Junit and Cucumber tests. I verified the log files after build, the Sonar build kicks off after normal maven build and picks only the Junit tests but not Cucumber tests.
I have the following versions and plugins available in my POM file. Please let me know if any one has come across the similar issue and fixed it. Many Thanks!
Junit version 4.11
Cucumber version 1.1.2
Sonar version 3.5.1
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<stopPort>8999</stopPort>
<stopKey>STOP</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8997</port>
<maxIdleTime>3600000</maxIdleTime>
</connector>
</connectors>
<systemProperties>
<systemProperty>
<name>dqs.env</name>
<value>local</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*RunDQSWsTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*RunDQSWsTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
RunDQSWsTest.java is the main file which runs all the .feature files