问题描述
这似乎在上周有效,现在却没有.
This seemed to be working last week and now it doesn't.
- 我们将Artifactory用作我们的Maven存储库.
- 我正在使用
deploy:deploy-file
目标部署jar和pom - 我们的Artifactory存储库需要身份验证才能部署.
- We use Artifactory as our Maven repository.
- I am deploying a jar and pom using the
deploy:deploy-file
goal - Our Artifactory repository requires authentication to deploy.
我可以通过将凭据嵌入到命令行中的服务器URL中来部署到存储库:
I can deploy to the repository by embedding my credentials in the server URL on the command line:
$ mvn deploy:deploy-file \
-Durl=http://deployer:[email protected]/artifactory/ext-release-local \
-Dfile=crypto.jar \
-DpomFile=pom.xml \
-Did=VeggieCorp
yadda...yadda...yadda...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.962s
[INFO] Finished at: Mon Aug 20 10:06:04 CDT 2012
[INFO] Final Memory: 4M/118M
[INFO] ------------------------------------------------------------------------
但是,整个部署都已记录下来,并且我的凭据将在日志中可见.因此,我希望能够在没有我的凭据的情况下在命令行上进行部署.为此,我有一个$HOME/.m2/settings.xml
文件:
However, that whole deployment gets logged and my credentials would be visible in the log. Therefore, I want to be able to deploy without my credentials on the command line. To do that, I have a $HOME/.m2/settings.xml
file:
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.veggiecorp.com</host>
<port>3128</port>
<nonProxyHosts>*.veggiecorp.com</nonProxyHosts>
</proxy>
</proxies>
<servers>
<server>
<id>VeggieCorp</id>
<username>deployer</username>
<password>swordfish</password>
</server>
</servers>
<profiles>
<profile>
<id>VeggieCorp</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>VeggieCorp</id>
<name>VeggieCorp's Maven Repository</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<url>http://repo.veggiecorp.com/artifactory/ext-release-local</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>VeggieCorp</activeProfile>
</activeProfiles>
</settings>
现在,我将尝试再次部署,但不要在URL中输入用户名和密码:
Now, I'll try deploying again, but without putting the user name and password in the URL:
$ mvn deploy:deploy-file \
-Durl=http://repo.veggiecorp.com/artifactory/ext-release-local \
-Dfile=crypto.jar \
-DpomFile=pom.xml \
-Did=VeggieCorp
yadda...yadda...yadda
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.751s
[INFO] Finished at: Mon Aug 20 10:17:15 CDT 2012
[INFO] Final Memory: 4M/119M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy- file (default-cli) on project crypto:
Failed to deploy artifacts: Could not transfer artifact
com.veggiecorp:crypto:jar:2.0.0 from/to remote-repository
(http://mvn.veggiecorp.com/artifactory/ext-release-local):
Failed to transfer file:
http://mvn.veggiecorp.com/artifactory/ext-release-local/com/veggiecorp/crypto/2.0.0/crypto-2.0.0.jar.
Return code is: 401, ReasonPhrase:Unauthorized. -> [Help 1]
(我已重新格式化输出以使其更易于查看.我收到401未经授权"错误)
(I've reformatted the output to make it easier to see. I'm getting a 401 "Unauthorized" error)
那么,我在做什么错?为什么我不能使用我的.settings.xml
文件来做我的凭证?代理部分可以正常工作,因为它可以从Maven主存储库中下载所需的插件.
So, what am I doing wrong? Why can't I use my .settings.xml
file to do my credentials? The proxy part does work because it can download the needed plugins from the main Maven repository.
推荐答案
您需要提供repositoryId=VeggieCorp
(而不是id
)属性,以便maven知道必须从哪个<server>
配置中读取凭据. /p>
You need to provide the repositoryId=VeggieCorp
(not id
) property so that maven knows from which <server>
configuration it has to read the credentials.
$ mvn deploy:deploy-file \
-Durl=http://repo.veggiecorp.com/artifactory/ext-release-local \
-Dfile=crypto.jar \
-DpomFile=pom.xml \
-DrepositoryId=VeggieCorp
请参见 http://maven.apache.org /plugins/maven-deploy-plugin/deploy-file-mojo.html
这篇关于Maven:尝试使用settings.xml文件中的凭据进行部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!