mavenrepositoryarchiva

why can't i upload artifact to archiva (Unauthorized), but i can download from it with admin user?


I'm working with archiva for about a year now,

I upload my jars manually through archiva GUI,and it's working fine.

Now I want to upload an artifact with maven deploy,the problem is that I get 401-Unauthorized. bare in mind that:

1.) I can download from this repository with no problem .

2.) I use admin user .

3.) I can upload with this user manually.

this is the log that I get:

[com:apinterface.parent] Downloading: http://xx.xx.xx.xx:9080/archiva/repository/snapshots/com/apinterface.parent/1.0-SNAPSHOT/maven-metadata.xml

[11:43:39][Step 1/3] [INFO] ------------------------------------------------------------------------
[11:43:39][Step 1/3] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project apinterface.parent: Failed to deploy artifacts: Could not transfer artifact com:apinterface.parent:pom:1.0-20140924.084338-1 from/to snapshots (http://xx.xx.xx.xx:9080/archiva/repository/snapshots): Failed to transfer file: http://xx.xx.xx.xx:9080/archiva/repository/snapshots/com/apinterface.parent/1.0-SNAPSHOT/apinterface.parent-1.0-20140924.084338-1.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]

Solution

  • This should be because you haven't configured Maven to use the Archiva Username/Password for uploading artifacts during the deploy phase.

    I assume you have already configured the distributionManagement section in your pom file.

    <distributionManagement>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Internal Snapshots</name>
            <url>http://xx.xx.xx.xx:9080/archiva/repository/snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>releases</id>
            <name>Internal Releases</name>
            <url>http://xx.xx.xx.xx:9080/archiva/repository/releases</url>
        </repository>
    </distributionManagement>
    

    You should have servers with matching ids in your Maven Settings file (like in the sample below) to configure the username/password which maven should use while uploading(deploy) the artifacts

    <settings>
      <servers>
        <server>
          <id>snapshots</id>
          <username>archiva-user</username>
          <password>archiva-pwd</password>
        </server>
        <server>
          <id>releases</id>
          <username>archiva-user</username>
          <password>archiva-pwd</password>
        </server>
      </servers>
    </settings>