405 Error when deploying to Maven Repository

If you’re getting a 405 error when trying to deploy a file to your Maven repository, it’s because the URL (as in -Durl=http://host.com/repo) you have specified is somehow incorrect.

For example, I was trying to deploy a file using the mvn deploy:deploy-file target to a Nexus repository, and I got the following error:

$ mvn deploy:deploy-file -DgroupId=com.austje.test -DartifactId=project -Dversion=1.0 -Dpackaging=jar -Dfile=project.jar -Durl=http://repo1.austje.com/ -DrepositoryId=MyReleases
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'deploy'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [deploy:deploy-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [deploy:deploy-file {execution: default-cli}]
Uploading: http://repo1.austje.com//com/austje/test/project/1.0/project-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://repo1.austje.com//com/austje/test/project/1.0/project-1.0.jar. Return code is: 405
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Mon Jan 25 11:15:25 CST 2010
[INFO] Final Memory: 5M/9M
[INFO] ------------------------------------------------------------------------
Looking at the line Uploading: http://repo1.austje.com//com/austje/test/project/1.0/project-1.0.jar, it’s pretty obvious that my url is wrong–that’s not where the artifact should be uploaded at all. Turns out I gave the repository server, but not the actual repository url! Changing my url parameter to reflect this

$ mvn deploy:deploy-file -DgroupId=com.austje.test -DartifactId=project -Dversion=1.0 -Dpackaging=jar -Dfile=workingTest.zip -Durl=http://repo1.austje.com/nexus/content/repositories/my-repo/ -DrepositoryId=MyReleases
fixed the issue, and I was able to deploy successfully.
Of course, this is not the only way you could screw up the url parameter. Among many possibilities, one tricky one I’ve seen is using http instead of https as the protocol.
Extra tip: If you fix the URL and are now getting return code 401, your credentials are incorrect. Try fixing them in your settings.xml file. You can test the credentials by going to the Nexus GUI and logging in. If those work, and you’re still not able to deploy via the command line, make sure the <id> in your <server> section of your settings.xml matches the <id> in the corresponding <repository> element.

6 thoughts on “405 Error when deploying to Maven Repository”

  1. It’d be appreciated if your pointed out in your code exactly where you made the mistake. I’ve been combing this for minutes trying to figure out where you made your mistake so I can relate it to where I’ve made mine. Just like a test case, show the actual and the expected. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *