执行mvn clean install下载node.exe返回401错误如何解决
你在CMD执行mvn clean install命令时收到如下报错:
[ERROR] Failed to execute goal com.github.eslett:frontend-maven-plugin:1.1:install-node-and-npm (Install NodeJS and NPM binaries) on project Hian-Direct-War: Could not download Node.js from: https://binaries.me.com/artifactory/igi-digital-maven-local/nodejs/v4.4.3/win-x64/node.exe: Got error code 401 from the server. -> [Help 1]
[ERROR]
[ERROR] 如需查看错误的完整堆栈跟踪信息,请使用-e参数重新运行Maven命令。
[ERROR] 使用-X参数重新运行Maven命令可开启全量调试日志。
[ERROR]
[ERROR] 如需了解该错误的更多信息及可能的解决方案,请阅读以下文章:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] 修正问题后,您可以使用以下命令继续构建:
[ERROR] mvn -rf :Hian-Direct-War
根因说明
报错返回码401是私有制品库身份认证未通过导致的,你通过浏览器可以正常下载是因为浏览器已经缓存了你登录制品库的账号凭证,但frontend-maven-plugin执行下载请求时未携带有效认证信息。
解决方案
你可以选择以下任意一种方式解决:
方案一:全局配置Maven制品库凭证(推荐)
- 找到Maven全局配置文件
settings.xml,默认路径为${USER_HOME}/.m2/settings.xml,如果该路径下没有该文件,可从Maven安装目录的conf/settings.xml拷贝一份到.m2目录 - 在配置文件的
<servers>节点下添加如下配置,替换为你自己的制品库账号、密码:
<server> <id>igi-digital-maven-local</id> <username>你的Artifactory账号</username> <password>你的Artifactory登录密码</password> </server>
配置完成后保存文件,重新执行mvn clean install即可。
方案二:单项目插件配置内置凭证
- 打开当前项目的
pom.xml文件,找到frontend-maven-plugin的配置节点,新增用户名、密码配置即可:
<plugin> <groupId>com.github.eslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.1</version> <configuration> <!-- 原有配置保持不变 --> <nodeVersion>v4.4.3</nodeVersion> <nodeDownloadRoot>https://binaries.me.com/artifactory/igi-digital-maven-local/nodejs/</nodeDownloadRoot> <!-- 新增以下两行认证配置 --> <username>你的Artifactory账号</username> <password>你的Artifactory登录密码</password> </configuration> </plugin>
注意:该方案会将明文密码写入项目pom文件,容易泄露账号信息,仅推荐临时本地调试使用
方案三:手动缓存文件跳过下载
如果你不想配置认证信息,可直接利用本地缓存跳过下载步骤:
- 手动在浏览器下载对应版本的
node.exe文件 - 将下载好的文件放到Maven缓存路径:
${USER_HOME}/.m2/repository/com/github/eslett/frontend-maven-plugin/1.1/node/win-x64/v4.4.3/,如果对应目录不存在可手动创建 - 重新执行
mvn clean install,插件会优先读取本地缓存文件,不会再发起远程下载请求
内容的提问来源于stack exchange,提问作者runnerpaul

