爛筆頭筆記:關於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校驗被破壞(本人測試似乎與公司網絡有關係)。

解決方法

插件默認使用了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(當然,安全性可能會引發問題,請酌情使用)。

參考資料

關於本問題的解決方法參考了:https://github.com/eirslett/frontend-maven-plugin/issues/278
插件更多使用技巧,請參閱:https://blog.csdn.net/weixin_34130269/article/details/86974309

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章