How to rebuild maven-metadata.xml in Artifactory?

◇◆丶佛笑我妖孽 提交于 2019-12-21 12:07:10

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/32353145/how-to-rebuild-maven-metadata-xml-in-artifactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!