2

Is there any order in which maven deploying artifacts? From what i see i can say that it uploads all artifacts and at last it updates maven-medata.xml files

http://localhost:8000/mavenrepository/test1/com/mypackage/mavenproject1/1.0-SNAPSHOT/maven-metadata.xml http://localhost:8000/mavenrepository/test1/com/mypackage/mavenproject1/maven-metadata.xml

Now is it guaranteed that maven always upload this 2 files at last, after uploading other artifacts?

carlspring
  • 31,231
  • 29
  • 115
  • 197
user93796
  • 18,749
  • 31
  • 94
  • 150

1 Answers1

4

Maven always deploys the artifact files in the same sequence. It usually looks something like this:

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ hello-world ---
Downloading: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/maven-metadata.xml
Uploading: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/hello-world-1.0-20160430.031713-1.jar
Uploaded: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/hello-world-1.0-20160430.031713-1.jar (3 KB at 11.5 KB/sec)
Uploading: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/hello-world-1.0-20160430.031713-1.pom
Uploaded: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/hello-world-1.0-20160430.031713-1.pom (2 KB at 41.6 KB/sec)
Downloading: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/maven-metadata.xml
Uploading: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/1.0-SNAPSHOT/maven-metadata.xml (798 B at 21.1 KB/sec)
Uploading: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/maven-metadata.xml
Uploaded: http://localhost:48080/storages/storage0/snapshots/org/foo/examples/hello-world/maven-metadata.xml (312 B at 8.7 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

As you can see, the first thing it does is it attempts to resolve the maven-metadata.xml file at the artifact level in order to figure out, if this artifact has other versions and whether to generate a brand new maven-metadata.xml file, or update the existing one, (if there is such), with the new version that it's deploying. The maven-metadata.xml file is always generated, or updated at the very end of the deployment.

There are three levels at which maven-metadata.xml files can be located:

  • Artifact level : This at the groupId/artifactId level, (for example, if your groupId is org.foo.examples and your artifactId is hello-world, the path will be org/foo/examples/hello-world/maven-metadata.xml). This is used for the management of base, or release versions.
  • Version level : This at the groupId/artifactId/version level, (for example, if your groupId is org.foo.examples and your artifactId is hello-world and version is 1.0-SNAPSHOT, the path will be org/foo/examples/hello-world/1.0-SNAPSHOT/maven-metadata.xml). This is used for the management of timestamped snapshots.
  • Plugin group level : This is at the plugin's groupId level and is used for the management of different plugins under the same plugin group.

For a very detailed explanation of how Maven metadata works, have a look at this article I've put together.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • 1
    Noticed the same thing as you mentioned . But I also observed a strange thing.When deploying source and java docs along with jar.maven-metadata.xml file is updated multiple times .Once for pom.xml and jar.xml , then once after source-jar is uploaded,and then once again when java docs is updated. But the maven-metadata.xml at package level/artifact level is updated only once after the jar pom and version level maven-metadata.xml is updated. In this case version level maven-metadata.xml is updated 2 more times after the packagelevel maven-metadata.xml is updated.Your thought? – user93796 May 12 '17 at 18:40
  • If your project produces several sub-artifacts, such as `javadocs`, `sources` and so on, these will all be added to the `maven-metadata.xml` file. The `maven-metadata.xml` file also includes your `pom`'s GAV (`groupId`, `artifactId`, `version`) coordinate information as well, as this is considered a sub-artifact as well. So, for any project that produces a `jar` (and no other sub-artifacts), your `maven-metadata.xml` file will also include the details for your `pom.xml`. This is all, of course, if you're using the `maven-deploy-plugin` (which is the default behaviour). – carlspring May 12 '17 at 18:47
  • I agree.My only concern is maven-metata.xml at package/artifact level is not the last file to be updated always as suggested by me in above comment.Do u agree? – user93796 May 12 '17 at 18:51
  • Try deploying an artifact and paste the whole output. The order i always the same. – carlspring May 12 '17 at 18:55
  • Why are you worried about this, if I may ask? What are you trying to do? – carlspring May 12 '17 at 18:55
  • 2
    Just curious. Was wondering how maven handles concurrent updates to same package version in repository at same time. Like 2 dev try to push same version of package in repository at same time.There is no transaction here. – user93796 May 12 '17 at 19:03
  • Well, I believe it's the repository server's responsibility to guarantee the thread-safety in this case. – carlspring May 12 '17 at 19:16
  • Hi Carl, the link you put in to your Maven metadata article is broken; is there another link available that works? Thanks. – RVS Dec 07 '19 at 01:37
  • I also have several lines prefixed with `Downloaded:` after the `Downloading` lines but not all the time. Any idea why? It looks to be related to the speed of the download. – рüффп Oct 07 '20 at 14:59
  • Not sure what you mean. Post another question and share a link. – carlspring Oct 08 '20 at 17:23