'Maven. Repository authentication

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)


Solution 1:[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

Solution 2:[2]

You settings.xml is missing the <servers> </servers> tags around your two <server> nodes. - https://maven.apache.org/settings.html#Servers

Also, I would avoid using generic id's like 'snapshots' and 'central'. Understandable if they are there for the purpose of SO.

The last update to this question didn't include the specific error code, but in the original error it was a 401 (Unauthorized) which leads me to believe that it's not able to find your servers authentication information due to invalid settings.xml

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JBaruch
Solution 2 Matt Johns