12

I encountered a quirky problem:

I used "mvn deploy" (Maven 3.3.9, Jenkins 2.45, Nexus 2.12.0) to deploy a snapshot jar to my nexus in jenkins, result as below (suppose the jar name is userdao.jar):

Uploaded: myNexusIp/nexus/content/repositories/snapshots/xxx/1.0-SNAPSHOT/userdao-1.0-20170512.111840-6.jar 
Uploaded: myNexusIp/nexus/content/repositories/snapshots/xxx/1.0-SNAPSHOT/maven-metadata.xml

The build was successful and everything was OK.

But when I built another maven project that depended above userdao.jar, error occurred as below:

Could not find artifact userdao:jar:1.0-20170512.111840-6 in public (http://myNexusIp/nexus/content/groups/public/)

After positioning I found that the timestamp in maven-metadata.xml in the nexus was more than a second than the actual jar's timestamp!
As below:

  • in maven-metadata.xml: 1.0-20170512.111840-6
  • actual existing snapshot jar: userdao-1.0-20170512.111839-6.jar

Because userdao-1.0-20170512.111840-6.jar did not exist in Nexus, the right one should be userdao-1.0-20170512.111839-6.jar, so it errors.

Who can tell me why and how to resolve it?

carlspring
  • 31,231
  • 29
  • 115
  • 197
IcyLemon
  • 139
  • 1
  • 5
  • Have you checked your log file that the userdao-.. is only uploaded once in your whole build... – khmarbaise May 14 '17 at 07:54
  • Hi khmarbaise,Thank you for your reminding, I found that userdao.jar's maven-metadata.xml was always updated 2 times in jenkins build log. And that if 2 updates were in a second there was no error, once 2 updates were in different seconds(e.g. one was 111839 and another was 111840), error occurred. – IcyLemon May 15 '17 at 01:22
  • Hi khmarbaise, why was uploading file executed twice and how can i resolve it? – IcyLemon May 15 '17 at 10:35
  • Hi how did you build the jar name can you please add your pom i am going through same problem that might help @IcyLemon – Manoj Jan 30 '18 at 17:34

6 Answers6

7

I actually found the opposite. After upgrading from Maven 3.3.9 to 3.5.0 I could reliably deploy artifacts where by the time stamps appearing in the metadata.xml files on Nexus were incorrect compared to the actual files that were deployed.

By downgrading (back to 3.3.9) everything worked correctly. The metadata.xml versions and timestamps matched always.

Perhaps it's something to do with the Maven 3.5.0 upgrade to remove Aether?

  • I agree. +1. I also seen instances of incorrect timestamp with maven 3.5.0. I stick with 3.3.9 for now for any `mvn deploy-file` task. – VonC Jun 06 '17 at 17:51
  • 1
    Yes, there is an issue in Maven 3.5.0: https://issues.apache.org/jira/browse/MDEPLOY-221 which was fixed in 3.5.1 – deveth0 Sep 29 '17 at 11:19
7

This has been confirmed a maven-3.5 issue https://issues.apache.org/jira/browse/MNG-6240 and a fixed applied. The release of maven-3.5.1 with the fix is voted here https://www.mail-archive.com/dev@maven.apache.org/msg114783.html

WuchenW
  • 71
  • 1
  • 2
  • 2
    Maven 3.5.2 is now [released](https://issues.apache.org/jira/projects/MNG/versions/12338964) , this issue should be fixed! – WuchenW Nov 02 '17 at 17:25
1

The first thing to try is to rebuild your metadata on the repo where you uploaded your snapshot artifact.

See "Managing Scheduled Tasks"

Rebuild Maven Metadata Files

This task will rebuild the maven-metadata.xml files with the correct information and will also validate the checksums (.md5/.sha1) for all files in the specified Repository/Group.
Typically this task is run manually to repair a corrupted repository.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi VonC, I already created a task "Rebuild Maven Metadata Files" in my Nexus and run it according to your advice, I will trace it, thanks a lot. – IcyLemon May 15 '17 at 01:59
  • Rebuild metadata is a repair operation, it isn't needed in normal cases. It's the responsibility of maven to download, update, and upload maven-metadata.xml files. As seen above, this issue was caused by a problem in the maven build (it was uploading twice). – rseddon May 15 '17 at 12:49
  • @rseddon the second upload should have updated the maven-metadata.xml, no? – VonC May 15 '17 at 12:51
  • @Vonc "Rebuild Maven Metadata Files" I created yesterday already executed but the issue still exists, so I guess that the root reason is that the maven-metadata.xml was uploated twice and the twice are not in the same second. I wonder why upload twice? – IcyLemon May 15 '17 at 23:57
1

I updated maven from 3.3.9 to 3.5.0, found that the maven-metadata.xml was uploaded once and the issue was resolved! So I guess this is a bug in maven 3.3.9, my current solution is updating maven to 3.5.0.

IcyLemon
  • 139
  • 1
  • 5
  • Interesting +1 I don't see that listed as a fixed issue in https://maven.apache.org/docs/3.5.0/release-notes.html though – VonC May 16 '17 at 11:16
  • I don't see either, but I am sure after testing repeatably : under the condition of without changing any other configuration, when using maven 3.3.9, the maven-metadata.xml is always uploaded TWICE, once switch to maven 3.5.0, it is uploaded only ONCE. – IcyLemon May 17 '17 at 02:55
0

I have faced same issue when using Maven 3.3.9. Tested by upgrading to Maven 3.5.4 but the issue still exists. The problem of maven-metadata.xml getting uploaded twice was due to spotbug maven plugin v3.1.3. It got resolved in the latest spotbug maven plugin version- 3.1.12 on which I have tested.

0

I was experiencing the same problem with maven 3.3.9. In my case, upgrading to maven 3.5.4 fixed the problem, no more "twice everything" in the default-deploy phase.

amutor
  • 1
  • 1