Maven. Repository authentication

爱⌒轻易说出口 提交于 2019-12-06 08:25:18

问题


I tried setup deploy to local repository:

-- settings.xml --

<server>
  <id>myrepo</id>
  <username>deployer</username>
  <password>123456</password>
</server>

-- pom.xml ---

<repositories>
    <repository>
        <id>myrepo</id>
        <url>http://myserver.com/artifactory/libs-release-local</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

when I execute "mvn deploy" I got error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.4:
deploy (default-deploy) on project xxx: Failed to deploy artifacts: Co
uld not transfer artifact xxx:xxx:war:0.1-20130527.121430-3 from/to myserver.com   
(http://myserver.com:8083/artifactory/libs-snapshot-local): Failed to transfer file: 
http://myserver.com:8083/artifactory/libs-snapshot-local/xxx/0.1-SNAPSHOT
/xxx-0.1-20130527.121430-3.war. Return code is: 401 

Artifactory log:

2013-05-27 16:14:38,158 [DENIED DEPLOY] libs-snapshot-local:xxx/0.1-SNAPSHOT
/xxx-0.1-20130527.121430-3.pom for anonymous/192.168.6.36.

If I change server/repository id to "myserver.com" - deploy WORK! But it does not suit me because that did not work plugin changelog with svn at myserver.com

I tried to add tags "profile" and "mirror" to server.xml and "distributionManagement" to pom.xml - getting the same error

server/repository id must be named ONLY as my server?

UPDATE1:

I remove tag 'repositories' from pom.xml and added tag 'distributionManagment':

--- pom.xml ---

<distributionManagement>
    <repository>
        <id>myrepo</id>
        <name>myrepo</name>
        <url>http://myserver.com/artifactory/libs-release-local</url>
    </repository>
    <snapshotRepository>
        <id>myrepo</id>
        <name>myrepo</name>
        <url>http://myserver.com/artifactory/libs-snapshots-local</url>
        <uniqueVersion>false</uniqueVersion>
    </snapshotRepository>
</distributionManagement>

(server.xml has not changed) - getting the same error "Failed to deploy..."

UPDATE2:

Try...

--- server.xml ---

<profiles>
    <profile>
        <id>artifactory</id>
        <repositories>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>central</id>
                <name>libs-release</name>
                <url>http://myserver.com/artifactory/libs-release-local</url>
            </repository>
            <repository>
                <snapshots />
                <id>snapshots</id>
                <name>libs-snapshot</name>
                <url>http://myserver.com/artifactory/libs-snapshot-local</url>
            </repository>
        </repositories>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>artifactory</activeProfile>
</activeProfiles>

<server>
    <id>snapshots</id>
    <username>deployer</username>
    <password>123456</password>
</server>
<server>
    <id>central</id>
    <username>deployer</username>
    <password>123456</password>
</server>

--- pom.xml ---

<distributionManagement>
    <repository>
        <id>central</id>
        <name>Internal Releases</name>
        <url>http://myserver.com/artifactory/libs-release-local</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Internal Snapshots</name>
        <url>http://myserver.com/artifactory/libs-snapshots-local</url>
        <uniqueVersion>false</uniqueVersion>
    </snapshotRepository>
</distributionManagement>

execute 'mvn deploy' - again error :(

Failed to deploy artifacts: Could not transfer artifact xxx:xxx:war:0.1-20130528.050526-1 from/to snapshots (http://myserver.com/artifactory/libs-snapshots-local)

回答1:


The 'repositories' tag is used for resolution, not for deployment. I'd speculate that the id of the repository under 'distributionManagment' tag is 'myserver.com', that's why it matches the server declaration in settings.xml



来源:https://stackoverflow.com/questions/16773427/maven-repository-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!