烂笔头笔记:关于frontend-maven-plugin插件无法下载nodejs和npm的问题

简介

frontend-maven-plugin是一个将maven与nodejs结合的插件,旨在maven生命周期中帮你下载并且本地(相对于项目来说)安装一份node和npm,并且执行npm install命令,并且还能执行其他的组合命令例如:Bower, Grunt, Gulp, Jspm, Karma, 或者 Webpack. 支持Windows, OS X 和Linux. 然而在默认情况下,在下载nodejs和npm时会报如下错误:

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6:install-node-and-npm (install node and npm) on project XXX:
 Could not download Node.js: Could not download https://nodejs.org/dist/v9.11.1/node-v9.11.1-linux-x64.tar.gz:
  sun.security.validator.ValidatorException: PKIX path building failed: 
  sun.security.provider.certpath.SunCertPathBuilderException:
  unable to find valid certification path to requested target -> [Help 1]

产生该问题的原因在于本地访问nodejs官方网站的过程当中SSL校验被破坏(本人测试似乎与公司网络有关系)。

解决方法

该maven插件默认使用了SSL校验机制,所以要么禁用该机制,要么将下载链接改一下。

<execution>
	<id>install node and npm</id>
	<goals>
		<goal>install-node-and-npm</goal>
	</goals>
	<configuration>
		<nodeDownloadRoot>http://nodejs.org/dist/</nodeDownloadRoot>
		<npmDownloadRoot>http://registry.npmjs.org/npm/-/</npmDownloadRoot>
		<nodeVersion>v9.11.1</nodeVersion>
	</configuration>
</execution>

在install-node-and-npm环节,增加配置:nodeDownloadRoot和npmDownloadRoot配置,并且将协议限制为http,而非使用默认的https(当然,安全性可能会引发问题,请酌情使用)。

2019年7月8日补充:当然,由于众所周知的原因,国内下载npm有可能会比较慢,所以也可以在npmDownloadRoot参数中配置淘宝的npm镜像:https://registry.npm.taobao.org,如果依然遇到该问题,也可以同样尝试使用http协议

2021年7月29日补充:原本写这篇文章,以为大家至少有maven的使用基础,一看execution段就应该知道改哪里了,结果还是有很多人问改哪。好吧,我贴得再详细一些:

<build>
    <plugins>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.6</version>
        <executions>
        	<execution>
        	...在这...
        	</execution>
        </executions>
      </plugin>
      ...
    </plugins>
</build>

参考资料

关于本问题的解决方法参考了:https://github.com/eirslett/frontend-maven-plugin/issues/278
插件更多使用技巧,请参阅:https://blog.csdn.net/weixin_34130269/article/details/86974309

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 20
    评论
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值