40

This seemed to be working last week and now it doesn't.

  • 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.

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: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] ------------------------------------------------------------------------

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>

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]

(I've reformatted the output to make it easier to see. I'm getting a 401 "Unauthorized" error)

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.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Hi, I have also same problem when I am applying release:perform. It shows error:-Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy).Can you help me in this. – JDGuide Sep 10 '13 at 13:06
  • @JDeveloper Did you see the Answer I checked below? It's very possible that you're passing in bad parameters. If that's not the issue, create a new question, and put all information (like i did). That's why mine got answered. Stefan Fersti saw my invalid parameters. – David W. Sep 10 '13 at 13:23
  • I have just answered in other channel. http://stackoverflow.com/questions/37543120/how-to-manually-deploy-artifacts-in-nexus-repository-manager-oss-3/39757111#39757111 – bpedroso Sep 28 '16 at 20:34

2 Answers2

56

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

See http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html

Stefan Ferstl
  • 5,135
  • 3
  • 33
  • 41
  • 2
    Thank you. I've been going through this for hours. Another idiotic oversight on my part: Not `-Did=VeggieCorp`. It should be `-`-`-DrepositoryId=VeggieCorp`. It now even works in Jenkins. Next up: Encrypt the password. – David W. Aug 20 '12 at 18:02
  • @JDeveloper You can use the `-Dversion=` property to specify a version number. [Here](http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html) you'll find all available properties to deploy files into your repository. A `pom.xml` file is not necessarily required but you need to specify at least `groupId`, `artifactId` and `version`. – Stefan Ferstl Jan 18 '14 at 00:07
  • Thank you @StefanFerstl . I need dynamically increment the version number.I am using jenkins for this deploy:deploy-file command. – JDGuide Jan 18 '14 at 15:16
  • @JDeveloper That could be difficult without your project being a maven project, i.e. not having a pom.xml. Maybe the [buildnumber-maven-plugin](http://mojo.codehaus.org/buildnumber-maven-plugin/create-mojo.html) will help you somehow. But I would strongly recommend you convert your project into a regular maven project and do [releases](http://maven.apache.org/maven-release/maven-release-plugin/) to "increase" your version number. – Stefan Ferstl Jan 18 '14 at 18:39
  • Yes mate , I am trying to use pom.xml with maven release plugin. – JDGuide Jan 18 '14 at 19:49
5

You can also specify your snapshot repository id in distributionManagement

<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>

the ids here should match ones in servers

xenoterracide
  • 16,274
  • 24
  • 118
  • 243