Maven:尝试使用settings.xml文件中的凭据进行部署

Dav*_* W. 35 deployment settings artifactory maven

这似乎在上周工作,现在它没有.

  • 我们使用Artifactory作为我们的Maven存储库.
  • 我正在使用deploy:deploy-file目标部署jar和pom
  • 我们的Artifactory存储库需要部署身份验证.

我可以通过在命令行上将我的凭据嵌入服务器URL来部署到存储库:

 $ mvn deploy:deploy-file \
     -Durl=http://deployer:swordfish@repo.veggiecorp.com/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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

但是,整个部署会被记录,我的凭据将在日志中显示.因此,我希望能够在命令行上没有我的凭据进行部署.为此,我有一个$HOME/.m2/settings.xml文件:

<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>
Run Code Online (Sandbox Code Playgroud)

现在,我将再次尝试部署,但不在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]
Run Code Online (Sandbox Code Playgroud)

(我已经重新格式化输出以便更容易看到.我收到401"未经授权"的错误)

那么,我做错了什么?为什么我不能使用我的.settings.xml文件来完成我的凭据?代理部分确实有效,因为它可以从主Maven存储库下载所需的插件.

Ste*_*stl 47

您需要提供repositoryId=VeggieCorp(非id)属性,以便maven知道<server>它必须从哪个配置读取凭据.

$ mvn deploy:deploy-file \
 -Durl=http://repo.veggiecorp.com/artifactory/ext-release-local \
 -Dfile=crypto.jar \
 -DpomFile=pom.xml \
 -DrepositoryId=VeggieCorp
Run Code Online (Sandbox Code Playgroud)

请参阅http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html

  • 谢谢.我已经经历了好几个小时.我的另一个愚蠢的疏忽:不是`-Did = VeggieCorp`.它应该是`-`-`-DrepositoryId = VeggieCorp`.它现在甚至可以在詹金斯工作.下一步:加密密码. (2认同)

xen*_*ide 5

您还可以在 distributionManagement 中指定您的快照存储库 ID

<distributionManagement>
<repository>
  <id>releases</id>
  <url>${env.MAVEN_RELEASE_REPOSITORY_URL}</url>
</repository>
<snapshotRepository>
  <id>snapshots</id>
  <url>${env.MAVEN_SNAPSHOT_REPOSITORY_URL}</url>
</snapshotRepository>
</distributionManagement>
Run Code Online (Sandbox Code Playgroud)

此处的 id 应与中的 id 匹配 servers