[maven] Error when deploying an artifact in Nexus

Im' getting an error when deploying an artifact in my own repository in a Nexus server: "Failed to deploy artifacts: Could not transfer artifact" "Failed to transfer file http:///my_artifact. Return code is: 400"

I have Nexus running with one custom repository my_repo with the next maven local configuration:

settings.xml

<server>
    <id>my_repo</id>
    <username>user</username>
    <password>pass</password>
 </server>
 ...
 <mirror>
    <id>my_repo</id>
    <name>Repo Mirror</name>
    <url><my_url_to_my_repo></url>
    <mirrorOf>*</mirrorOf>
  </mirror>
  • user has permissions to create/read/write into my_repo -

pom.xml

<distributionManagement>
        <repository>
            <id>my_repo</id>
            <name>my_repo</name>
            <url><my_url_to_my_repo></url>
            <layout>default</layout>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Snapshots</name>
            <url><my_url_to_my_snapshot_repo></url>
        </snapshotRepository>
    </distributionManagement>

and then I execute

mvn deploy

and get the error. Any idea?

This question is related to maven deployment pom.xml nexus

The answer is


In the rare event that you need to redeploy the SAME STABLE artifact to Nexus, it will fail by default. If you then delete the artifact from Nexus (via the web interface) for the purpose of deploying it again, the deploy will still fail, since just removing the e.g. jar or pom does not clear other files still laying around in the directory. You need to log onto the box and delete the directory in its entirety.


  • in the parent pom application==> Version put the tag as follows: x.x.x-SNAPSHOT

example :0.0.1-SNAPSHOT

  • "-SNAPSHOT" : is very important

400 Bad Request will be returned if you attempt to:

  1. Deploy a snapshot artifact (or version) ending in -SNAPSHOT to a release repository
  2. Deploy a release artifact (version not ending in -SNAPSHOT) to a snapshot repository
  3. Deploy the same version of a release artifact more than once to a release repository

If any of the above answers worked out, You can create new artifact directly from the admin side of (NEXUS Screen shot attached below).

  1. Login to nexus UI http://YOUR_URL:8081/nexus( username: admin default password: admin123 )
  2. Click repositories on the left side then click the repo, For eg: click release.
  3. Choose artifact Upload (last tab).
  4. Choose GAV definition as GAV Param- Then enter your groupid , artifact id and version .
  5. Choose Jar file.
  6. Click upload artifact. Thats it !

Now you will be able to add the corrsponding in your project.(screenshot below)

enter image description here


I had this exact problem today and the problem was that the version I was trying to release:perform was already in the Nexus repo.

In my case this was likely due to a network disconnect during an earlier invocation of release:perform. Even though I lost my connection, it appears the release succeeded.


Ensure that not exists already (artifact and version) in nexus (as release). In that case return Bad Request.


Cause of problem for me was -source.jars was getting uploaded twice (with maven-source-plugin) as mentioned as one of the cause in accepted answer. Redirecting to answer that I referred: Maven release plugin fails : source artifacts getting deployed twice


I had the same problem today with the addition "Return code is: 400, ReasonPhrase: Bad Request." which turned out to be the "artifact is already deployed with that version if it is a release" problem from answer above enter link description here

One solution not mentioned yet is to configure Nexus to allow redeployment into a Release repository. Maybe not a best practice, because this is set for a reason, you nevertheless could go to "Access Settings" in your Nexus repositories´ "Configuration"-Tab and set the "Deployment Policy" to "Allow Redeploy".


This can also happen if you have a naming policy around version, prohibiting the version# you are trying to deploy. In my case I was trying to upload a version (to release repo) 2.0.1 but later found out that our nexus configuration doesn't allow anything other than whole number for releases.

I tried later with version 2 and deployed it successfully.

The error message definitely dosen't help:

Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases-xxx. -> [Help 1]

A better message could have been version 2.0.1 violates naming policy


For 400 error, check the repository "Deployment policy" usually its "Disable redeploy". Most of the time your library version is already there that is why you received a message "Could not PUT put 'https://yoururl/some.jar'. Received status code 400 from server: Repository does not allow updating assets: "your repository name"

So, you have a few options to resolve this. 1- allow redeploy 2- delete the version from your repository which you are trying to upload 3- change the version number


Just to create a separate answer. The answer is actually found in a comment for the accepted answer.

Try changing the version of your artefact to end with -SNAPSHOT.


Server id should match with the repository id of maven settings.xml


Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to deployment

error: This is probably not a problem with npm. There is likely additional logging output above Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature) repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter "Untrusted App Developer" message when installing enterprise iOS Application How do I copy directories recursively with gulp? How to deploy correctly when using Composer's develop / production switch? Enterprise app deployment doesn't work on iOS 7.1 Can not deserialize instance of java.lang.String out of START_OBJECT token Run command on the Ansible host Error when deploying an artifact in Nexus

Examples related to pom.xml

Why am I getting Unknown error in line 1 of pom.xml? Maven:Non-resolvable parent POM and 'parent.relativePath' points at wrong local POM Meaning of ${project.basedir} in pom.xml Maven and Spring Boot - non resolvable parent pom - repo.spring.io (Unknown host) Maven: How do I activate a profile from command line? repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter What is <scope> under <dependency> in pom.xml for? The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path Maven error in eclipse (pom.xml) : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 Missing artifact com.oracle:ojdbc6:jar:11.2.0 in pom.xml

Examples related to nexus

How to manually deploy artifacts in Nexus Repository Manager OSS 3 What is the difference between Nexus and Maven? Error when deploying an artifact in Nexus Maven error: Not authorized, ReasonPhrase:Unauthorized Upload artifacts to Nexus, without Maven How to specify maven's distributionManagement organisation wide?