--force option frontend maven plugin - maven

Is there anyway how to use --force option for frontend maven plugin ?
[INFO] --- frontend-maven-plugin:1.12.1:npm (npm install) # justine ---
[INFO] npm ERR! code ERESOLVE
[INFO] npm ERR! ERESOLVE unable to resolve dependency tree

It should look like this :
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install --force</arguments>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
</configuration>
</execution>

Related

Output the frontend maven plugin results to a file

I have a frontend-maven-plugin in a super-pom which is used to build the npm artifacts. As part of this step, I decided to build a npm dependency tree and capture the results in a file.
I tried the below step which prints the dependency in StandardOut, is there a way to re-direct this to a file ?
<execution>
<id>npm tree</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>list --prod --json</arguments>
</configuration>
</execution>
Looked at the npm list, but it doesn't seem to have any file o/p option.
I stumbled across the same issue and finally worked out a solution.
Just add an entry unter the scripts-Tag in your package.json like this:
"scripts": {
"versions-out": "npm list -prod -json > versions.txt ",
"v2-out": "npm --version > npmv.txt ",
}
Then in your pom, just call the script with:
<execution>
<id>library versions</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script versions-out</arguments>
</configuration>
</execution>
I also ran the v2-out the same way, to ensure that this command uses the npm version specified in the pom rather then my local installation. Yes. it does!

frontend-maven-plugin fails npm install

I can use the command line to run npm install and npm run build on my project but when I try to use the frontend-maven-plugin it fails with the following error
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] app_name [pom]
[INFO] frontend [jar]
[INFO] backend [jar]
[INFO]
[INFO] ---------------------< com.flareback-domain:app_name >----------------------
[INFO] Building app_name 1.0-SNAPSHOT [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # app_name ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # app_name ---
[INFO] Installing /Users/flareback/code/app_name/pom.xml to /Users/flareback/.m2/repository/com/flareback-domain/app_name/1.0-SNAPSHOT/app_name-1.0-SNAPSHOT.pom
[INFO]
[INFO] ----------------------< com.flareback-domain:frontend >----------------------
[INFO] Building frontend 1.0-SNAPSHOT [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # frontend ---
[INFO] Deleting /Users/flareback/code/app_name/frontend/target
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:install-node-and-npm (install node and npm) # frontend ---
[INFO] Node v12.14.1 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm install) # frontend ---
[INFO] Running 'npm install' in /Users/flareback/code/app_name/frontend
[INFO] internal/modules/cjs/loader.js:796
[INFO] throw err;
[INFO] ^
[INFO]
[INFO] Error: Cannot find module './internal/streams/buffer_list'
[INFO] Require stack:
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/readable-stream/readable.js
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-stream.js
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-group.js
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/index.js
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/log.js
[INFO] - /Users/flareback/code/app_name/frontend/node/node_modules/npm/bin/npm-cli.js
[INFO] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
[INFO] at Function.Module._load (internal/modules/cjs/loader.js:686:27)
[INFO] at Module.require (internal/modules/cjs/loader.js:848:19)
[INFO] at require (internal/modules/cjs/helpers.js:74:18)
[INFO] at Object.<anonymous> (/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:72:18)
[INFO] at Module._compile (internal/modules/cjs/loader.js:955:30)
[INFO] at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
[INFO] at Module.load (internal/modules/cjs/loader.js:811:32)
[INFO] at Function.Module._load (internal/modules/cjs/loader.js:723:14)
[INFO] at Module.require (internal/modules/cjs/loader.js:848:19) {
[INFO] code: 'MODULE_NOT_FOUND',
[INFO] requireStack: [
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js',
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/readable-stream/readable.js',
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-stream.js',
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-group.js',
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/index.js',
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/node_modules/npmlog/log.js',
[INFO] '/Users/flareback/code/app_name/frontend/node/node_modules/npm/bin/npm-cli.js'
[INFO] ]
[INFO] }
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for app_name 1.0-SNAPSHOT:
[INFO]
[INFO] app_name ........................................... SUCCESS [ 0.279 s]
[INFO] frontend ........................................... FAILURE [ 0.438 s]
[INFO] backend ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.902 s
[INFO] Finished at: 2020-02-04T10:34:21-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm install) on project frontend: Failed to run task: 'npm install' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :frontend
My frontend pom file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>frontend</artifactId>
<parent>
<artifactId>app_name</artifactId>
<groupId>com.flareback-domain</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<frontend-maven-plugin.version>1.9.1</frontend-maven-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v12.14.1</nodeVersion>
</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 build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I changed my pom to use a different node version
<nodeVersion>v9.11.1</nodeVersion>
I then ran mvn clean install. That failed but it got past the install part and failed on the run build. Then I switched back to <nodeVersion>v12.14.1</nodeVersion> and re-ran the mvn clean install and it worked.
I added node and npm version same as my local machine version then this error disappered
<properties>
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
<node.version>v12.18.1</node.version>
<npm.version>6.14.5</npm.version>
</properties>
I have this error but my issue is that I added "v" before npm version.
If you get node version, node --version you'll get "v12.3.4" but if you get npm version, you 'll get "5.4.3".
In pom file,
<properties>
<node.version>v16.13.0</node.version>
<npm.version>8.1.0</npm.version> <java.version>11</java.version>
</properties>
I upgraded the Node LTS version and now it works.
It's node version issue. Also possible that your global node version mismatches.
I have implemented following code with node version 10.16.0
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.7.6</version>
<configuration>
<nodeVersion>v10.16.0</nodeVersion>
<npmVersion>6.10.2</npmVersion>
<workingDirectory>./angular</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run-script build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run-script build</arguments>
</configuration>
</execution>
</executions>
</plugin>
If this still not work, try clearing npm cache with force attribute
npm cache clean --force
Thanks for reading.
Had the same problem. Turn out I just had forgotten to add the 'v' in my node version.
change node version and npm version in the pom file to the node and npm versions that are installed in your local machine. Then run a mvn clean install. It will solve your issue.
This is how i did it.
(1) This is the node and npm versions that are in the project earlier
node - v10.15.2
npm - 6.4.1
(2)This is after i changed the versions
node - v14.19.1
npm - 6.14.16
(3)Then run mvn clean install.
Your problem sould be solved.

maven-jaxb2-plugin fails when running downloaded purchase order sample

I downloaded the sample project maven-jaxb2-plugin-sample-po-0.12.2-maven-src.zip and it fails with an error as shown below:
[INFO] --- maven-jaxb2-plugin:0.13.0:generate (default) # maven-jaxb2-plugin-sample-po-maven ---
[WARNING] The POM for org.glassfish.jaxb:jaxb-xjc:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Error injecting: org.jvnet.mjiip.v_2.XJC2Mojo
java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener
This error is quite strange since all I doing is just running mvn clean install
Does anyone know what's going on or seen this error before?
maven-jaxb2-plugin requires to be executed by a jdk and not a jre.
This does work
set JAVA_HOME=c:\Program Files\Java\jdk1.8.0_92
mvn package
This does not work
set JAVA_HOME=c:\Program Files\Java\jre1.8.0_92
mvn package
When the plugin is used in Eclipse/STS, then Eclipse/STS must be started using a JDK. eclipse.ini
I did face similar issue. I did resolve it by making changes in pom.xml as suggested at https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-a-Specific-JAXB-Version
My plugin configuration is.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb22-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
</plugin>

maven-frontend-plugin build error

I have been working on getting angular 2 setup in eclipse. I ran into an error when setting up maven. I am relatively new to maven and I am unsure on how to overcome the error. Any help would be appreciated.
[INFO] --- frontend-maven-plugin:1.0:npm (npm install) # BudgetCalculator ---
[INFO] Running 'npm install' in /Users/csexton/Eclipse-Workspace/REST/BudgetCalculator
[INFO] budget_calculator#1.0.0 /Users/csexton/Eclipse-Workspace/REST/BudgetCalculator
[INFO] +-- angular2#2.0.0-beta.17
[INFO] +-- UNMET PEER DEPENDENCY es6-shim#^0.35.0
[INFO] +-- UNMET PEER DEPENDENCY reflect-metadata#0.1.2
[INFO] +-- UNMET PEER DEPENDENCY rxjs#5.0.0-beta.6
[INFO] `-- UNMET PEER DEPENDENCY zone.js#^0.6.12
[INFO]
[WARNING] npm WARN EPEERINVALID angular2#2.0.0-beta.17 requires a peer of es6-shim#^0.35.0 but none was installed.
[WARNING] npm WARN EPEERINVALID angular2#2.0.0-beta.17 requires a peer of reflect-metadata#0.1.2 but none was installed.
[WARNING] npm WARN EPEERINVALID angular2#2.0.0-beta.17 requires a peer of rxjs#5.0.0-beta.6 but none was installed.
[WARNING] npm WARN EPEERINVALID angular2#2.0.0-beta.17 requires a peer of zone.js#^0.6.12 but none was installed.
[WARNING] npm WARN EPACKAGEJSON budget_calculator#1.0.0 No description
[WARNING] npm WARN EPACKAGEJSON budget_calculator#1.0.0 No repository field.
[WARNING] npm WARN EPACKAGEJSON budget_calculator#1.0.0 No license field.
[INFO]
[INFO] --- frontend-maven-plugin:1.0:npm (npm run build) # BudgetCalculator ---
[INFO] Running 'npm run build' in /Users/csexton/Eclipse-Workspace/REST/BudgetCalculator
[ERROR] npm ERR! Darwin 15.4.0
[ERROR] npm ERR! argv "/Users/csexton/Eclipse-Workspace/REST/BudgetCalculator/node/node" "/Users/csexton/Eclipse-Workspace/REST/BudgetCalculator/node/node_modules/npm/bin/npm-cli.js" "run" "build"
[ERROR] npm ERR! node v5.3.0
[ERROR] npm ERR! npm v3.3.12
[ERROR]
[ERROR] npm ERR! missing script: build
[ERROR] npm ERR!
[ERROR] npm ERR! If you need help, you may report this error at:
[ERROR] npm ERR! <https://github.com/npm/npm/issues>
[ERROR]
[ERROR] npm ERR! Please include the following file with any support request:
[ERROR] npm ERR! /Users/csexton/Eclipse-Workspace/REST/BudgetCalculator/npm-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.356 s
[INFO] Finished at: 2016-05-29T14:36:25-04:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------
two things I can see right off that could be problems but I have no idea how to solve or why it caused the error: npm ERR! missing script: build &
[INFO] +-- UNMET PEER DEPENDENCY es6-shim#^0.35.0
[INFO] +-- UNMET PEER DEPENDENCY reflect-metadata#0.1.2
[INFO] +-- UNMET PEER DEPENDENCY rxjs#5.0.0-beta.6
[INFO] `-- UNMET PEER DEPENDENCY zone.js#^0.6.12
package.json file
{
"name": "budget_calculator",
"version": "1.0.0",
"dependencies": {
"angular2": "2.0.0-beta.17",
"es6-shim":"^0.35.0",
"reflect-metadata":"0.1.2",
"rxjs":"5.0.0-beta.6",
"zone.js":"^0.6.12"
}
}
pom.xml portion of what I used to install plugins
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</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>
</executions>
</plugin>
</plugins>
</build>
It seems you are missing these dependencies in package.json
"dependencies": {
...
"es6-shim":"^0.35.0",
"reflect-metadata":"0.1.2",
"rxjs":"5.0.0-beta.6",
"zone.js":"^0.6.12"
}
You are also missing a script named build, you can add it in package.json, because in you pom.xml, you have <id>npm run build</id>
{
...
"scripts": {
"build": "..."
},
"dependencies": {
...
}
}

Passing Working Directory to npm in exec-maven-plugin

I am trying to run npm as part of my maven build. I am using exec-maven-plugin and here is my plugin section from pom.xml
<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>build</argument>
</arguments>
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
How ever when i run mvn clean package or mvn generate-sources npm is not running.
In my package.json i have the following scripts.
"scripts": {
"start": "npm run build && serve .",
"build": "npm run build-js && npm run build-css",
"watch": "npm run watch-js & npm run watch-css & serve .",
"watch-build": "npm run watch-js && npm run watch-css && npm run build-js && npm run build-css && serve .",
"test": "npm run lint -s && npm run build",
"build-css": "rework-npm index.css | cleancss -o build/build.css",
"build-js": "browserify --extension=.jsx --extension=.js src/app.jsx > build/build.js",
"watch-js": "watchify --extension=.jsx --extension=.js src/app.jsx -o build/build.js --debug --verbose",
"watch-css": "nodemon -e css --ignore build/build.css --exec 'rework-npm index.css -o build/build.css'",
"lint-eslint": "eslint .",
"lint-jscs": "jscs .",
"lint": "npm run lint-eslint && npm run lint-jscs"
}
And hence i am calling build.
Earlier when i used npm install i did see the npm packages being installed.
Also how do i specify the working directory for npm ??
I am passing using and that's where the package.json is located.
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
Thanks
You need to execute npm run build to run an npm script, but you are executing npm build, which is an npm lifecycle event.
<execution>
<id>npm run build</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>

Resources