7

We're using Artifactory 3.9.2 and had to merge parts of two repositories (by copying over the artifacts) which had the same (SNAPSHOT-versioned) artifact. This screwed up the maven-metadata.xml. In Nexus its possible to simply rebuild the metadata for this artifact and let the repository manager sort out things for you. I can't seem to find any links/explanations on how to do this with Artifactory. Could somebody please tell me how I can do this?

carlspring
  • 27,224
  • 23
  • 101
  • 178

3 Answers3

16

I'm not sure if this is possible in the UI, but you can do it using the REST API. Try posting a request using curl:

curl -v -X POST http://artifactory/artifactory/api/maven/calculateMetadata/my-repository/com/foo/bar

They decided to call it "calculate metadata" instead of "rebuild metadata" which is not very suitable IMHO.

carlspring
  • 27,224
  • 23
  • 101
  • 178
tftd
  • 14,540
  • 8
  • 50
  • 99
  • 2
    Well, I wouldn't necessarily say it's wrong, it's just hard to find the documentation when you're looking for a different term than the one most people seem to be using. – carlspring Sep 04 '15 at 17:01
  • documentation: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-CalculateMavenMetadata – vikingsteve Dec 01 '16 at 10:05
5

We are using artifactory 4.4.2 and I came here since the maven-metadata.xml files were missing from folders in our artifactory where we had deployed war files manually using the REST API.

The important thing to note is that calculateMetadata will not do anything if there are no pom.xml files in place! (source)

Therefore, after we deployed com/company/project/art/1.0/art-1.0.war, we needed to make a "blank" art-1.0.pom and deploy it to the correct place.

Here's an example of a blank pom.

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/xsd/maven-4.0.0.xsd" 
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company.project</groupId>
  <artifactId>art</artifactId>
  <version>1.0</version>
  <description>POM was created from a script</description>
</project>

Now, the second thing we notice - once you deploy art-1.0.pom the maven metadata is calculcated automatically (at least, for a local repo with default maven2 layout).

Therefore we didnt need to call calculateMetadata via REST api at all - it seems to be automatic whenever you upload a pom.

vikingsteve
  • 34,284
  • 19
  • 101
  • 142
  • This is correct. No Maven-based repository's metadata can be regenerated, unless there is a `pom.xml`. I mean on what will the `maven-metadata.xml` be based? This is the same for all repository managers. – carlspring Dec 01 '16 at 10:55
  • Well the group, artifact and version are available in the repository path and the artifact name. So I was helpful that calculateMetadata would work without pom's being present. Alas I was wrong and had to learn this after trial and error. Thank you for your comment and also your answer above, @carlspring. – vikingsteve Dec 01 '16 at 11:54
  • In theory, you're right that this should be more than enough data. However, you can have multiple extensions per artifact (for example `.jar`, `.dll`, etc) and you can have classifiers and checksums... and the repository manager has to figure out what your artifacts really are... What the main artifact is, what the sub-artifacts are, what are checksums, archives, etc... and, while it can be implemented, you can't be sure whether or not the actual user may be doing something incorrectly, or abusing the system... So, I guess this is why repository managers are not going so far. – carlspring Dec 01 '16 at 12:40
  • Apart from that, Maven-based artifacts also contain the `pom.xml` under `META-INF/maven/${groupId}/${artifactId}/pom.xml` and you could argue that if the `.pom` of the artifact is not present on the file system, then you could regenerate the `maven-metadata.xml` based on the on in the `META-INF`, but... if you have a massive amount of artifacts (and versions of them), this can take a lot longer than just scanning the file system directly. So... the performance could be quite bad, hence nobody's doing it like this (as far as I know)... – carlspring Dec 01 '16 at 12:44
  • Correct. And in fact if you unpack the `pom.xml` from `META-INF` and it refers to a pom which is not available in your repos or from maven central then builds will fail! Experienced this today - so we crafted "blank" pom's with just `artifactId`, `groupId`, `version` and a comment, and it worked fine. – vikingsteve Dec 01 '16 at 14:28
  • 1
    Well, this will basically break your `` and transitive dependencies for any artifacts depending on these... Also if these are released versions and the `pom` files have already been downloaded for these, then they will have to be removed from the local caches... – carlspring Dec 01 '16 at 14:35
1

The accepted answer talks about Artifactory REST API solution, which indeed is the correct solution. But, due to proxy configured in my organization, it did not work for me. Also, I had to specify basic authentication details. So, posting the complete command that worked for me :-

curl -x http://{proxy_host}:{proxy_port} -kLu {username}:{password} -X POST https://{artifactory-link}/artifactory/api/maven/calculateMetadata/{repository-name}/{location}

This is the documentation of the REST API.

Rumit Patel
  • 3,667
  • 10
  • 38
  • 49
Yogiraj Kulkarni
  • 151
  • 3
  • 11