Why am I getting a “401 Unauthorized” error in Maven?

I’ve had similar errors when trying to deploy a Gradle artefact to a Nexus Sonatype repository. You will get a 401 Unauthorized error if you supply the wrong credentials (password etc). You also get an error (and off the top of my head is also a 401) if you try to publish something to a releases repository and that version already exists in the repository. So you might find that by publishing from the command line it works, but then when you do it from a script it fails (because it didn’t exist in the repository the first time around). Either publish using a different version number, or delete the old artefact on the server and republish.

The SNAPSHOTS repository (as opposed to the releases repository) allows you to overwrite a similarly numbered version, but your version number should have “-SNAPSHOT” at the end of it.

Leave a Comment