Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make maven-metadata.xml have the same timestamp as the artifact wen deployed with maven?

I have a Nexus 3 which I deploy some artifacts from Jenkins with "mvn deploy". I have A LOT of modules 500+. The build looks kind of like this:

mvn clean package -DskipTests -DskipITs -T C1

mvn install -DskipTests -DskipITs -T C1

mvn deploy --quiet -DskipTests -DskipITs -Dmaven.validate.skip=true -Dmaven.compile.skip=true -Dmaven.test.skip=true -Dmaven.package.skip=true -Dmaven.integration-test.skip=true -Dmaven.verify.skip=true -T C1

The problem is that from time to time my artifacts have a timestamp while the metadata has a different timestamp. 1 second difference usually.

This is what I see in nexus at https://mynexus.com/repository/snapshots/com/company/my-artifact/1.0.0-SNAPSHOT/maven-metadata.xml

<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
  <groupId>com.company</groupId>
  <artifactId>my-artifact</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <versioning>
    <snapshot>
      <timestamp>20170613.140447</timestamp>
      <buildNumber>1</buildNumber>
    </snapshot>
    <lastUpdated>20170613140447</lastUpdated>
    <snapshotVersions>
      <snapshotVersion>
        <extension>war</extension>
        <value>1.0.0-20170613.140447-1</value>
        <updated>20170613140447</updated>
      </snapshotVersion>
      <snapshotVersion>
        <extension>pom</extension>
        <value>1.0.0-20170613.140447-1</value>
        <updated>20170613140447</updated>
      </snapshotVersion>
    </snapshotVersions>
  </versioning>
</metadata>

Judging the maven-metadata.xml, the artifact URL should be this:

https://mynexus.com/repository/snapshots/com/company/my-artifact/1.0.0-SNAPSHOT/my-artifact/1.0.0-20170613.140447-1.war

But it is not. Instead, the artifact is at this location:

https://mynexus.com/repository/snapshots/com/company/my-artifact/1.0.0-SNAPSHOT/my-artifact/1.0.0-20170613.140446-1.war

mvn --version OpenJDK 64-Bit Server VM Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00) Maven home: /usr/local/apache-maven Java version: 1.8.0_131, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.4.0-64-generic", arch: "amd64", family: "unix"

The version of maven-deploy-plugin is 2.8.2

What am I doing wrong? How can I fix this? Thank you!

like image 642
ddreian Avatar asked Jun 14 '17 13:06

ddreian


People also ask

Why is Maven downloading the Maven metadata XML every time?

Maven does this because your dependency is in a SNAPSHOT version and maven has no way to detect any changes made to that snapshot version in the repository. Release your artifact and change the version in pom. xml to that version and maven will no longer fetch the metadata file.

Where is Maven metadata local XML located?

The file at https://repo1.maven.org/maven2/com/octopus/randomquotes/maven-metadata.xml is created when a Maven artifact is published. It lists various details about the artifacts that have been published, like version number and the dates when the artifact was last updated.

What is Maven metadata XML used for?

This is used for storing the top-level versions of artifacts. For example, if an artifact has versions 1.0 , 1.1 , 1.2 , this maven-metadata. xml will only contain version information about them.

What is metadata in artifact?

Artifact metadata consists of a key, a value, and a namespace. Existing metadata from a component's POM is given a urn:maven namespace and custom attributes are stored under the urn:nexus/user namespace.


1 Answers

This is a bug in Maven 3.5.0 and and will be resolved whenever 3.5.1 is released.

The original bug-report targed the deploy-plugin (https://issues.apache.org/jira/browse/MDEPLOY-221) however it's an issue with maven core: https://issues.apache.org/jira/browse/MNG-6240.

We hit the same issue at my work and after some digging and searching on mavens issue tracker I found the above links. I would suggest downgrading while waiting for 3.5.1 to come out.

like image 143
cfw Avatar answered Oct 13 '22 16:10

cfw