Error "Could not transfer metadata" running Maven deploy with Jenkins

15,441

Solution 1

This is issue with the credentials.

find out which settings.xml maven is using. mvn -v

then in that file update the section with correct credentials

 <server>
      <id>deploymentRepo</id>
      <username>deployment</username>
      <password>deployment</password>
    </server>

Now try it:)

Solution 2

The easiest way to resolve this is to delete the dependencies or artifacts which maven has appended with the .lastUpdated prefix. Only after that can you successfully Update Dependencies of your maven project.

For Unix Users:

  1. find ~/.m2 -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;

  2. Right click your project and choose Update Dependencies

For Windows Users:

  1. CD (change directory) to <user-directory>\.m2\repository
  2. execute this command for /r %i in (*.lastUpdated) do del %i
  3. Right click your project and choose Update Dependencies
Share:
15,441
Eria
Author by

Eria

Updated on June 05, 2022

Comments

  • Eria
    Eria almost 2 years

    I have 2 Maven projects, which are deployed daily in a Nexus snapshots repository by Jenkins builds. For one project, everything works fine. For the second one, I have the error below every time Jenkins runs mvn deploy :

    [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ my-second-project ---
    [INFO] Downloading: http://my.nexus/content/repositories/snapshots/fr/domain/my-second-project/0.18.0-SNAPSHOT/maven-metadata.xml
    [WARNING] Could not transfer metadata fr.domain:my-second-project:0.18.0-SNAPSHOT/maven-metadata.xml from/to my.nexus (http://my.nexus/content/repositories/snapshots): Access denied to: http://my.nexus/content/repositories/snapshots/fr/domain/my-second-project/0.18.0-SNAPSHOT/maven-metadata.xml , ReasonPhrase:Forbidden.
    

    The 2 projects have exactly the same version.

    I tried to run mvn help:effective-settings on both Jenkins builds, instead of mvn deploy : it returns exactly the same settings for both projects. But one deploys on Nexus and the other does not...

    Edit: mvn help:effective-pom doesn't show any helpful difference either. Except for the project name and some dependencies, they are the same.

    In the case of the second project, it has never been deployed on Nexus. So metadata doesn't exists yet. But I tried to tail the nexus request.log file, and it's never hit when Jenkins runs mvn deployon the second project. I have no trace of that call.

    Does anyone have an idea ?


    Edit: I've finally found out that the company proxy is throwing the "Forbidden" error. Which is weird, because in the settings.xml Maven configuration file, I have the following :

    <proxy>
        <id>****</id>
        <active>true</true>
        <protocol>http</protocol>
        <host>**********</host>
        <port>8080</port>
        <nonProxyHosts>my.nexus|127.0.0.1|...</nonProxyHosts>
    </proxy>
    

    The job that fails is ignoring the "nonProxyHosts" part : the proxy defined in the config is called and throws the error. The job that builds normally doesn't call the proxy (expected behaviour).

    I'm still looking for ideas about the reason for this behaviour...