How do I find the latest version of an artifact from a maven repository

亡梦爱人 提交于 2019-12-03 02:57:29

问题


As part of an automated deployment I need a script to download the latest version of an artifact from our internal repository.

Ideally this script will be with ant or a unix shell script.

So for example:

I have myArtifact.war and it has versions 1.0 , 1.1 and 2.0 - I need the script given the correct group id and artifact id to retrieve version 2.0 from our maven repository (currently using artifactory).

Is there any easy way to do this?


回答1:


You can parse the maven-metadata.xml to see what versions are available, and which version is the "release" version. See this answer about plugin versions for more details.

If you are using Nexus, you can use the REST API to query the repository. You can also use the REST client API to simplify your processing.

To update the release version, activate the release-profile in the Maven super POM when you do mvn deploy. You can do this by adding -Prelease-profile or -DperformRelease=true to the command line.

The profile is activate by default in the maven-release-plugin's perform goal. It is controlled by the useReleaseProfile property. See the release-perform goal's documentation for more details.




回答2:


You can use the Maven Dependency Plugin goal get together with LATEST as version for your artifact:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get
    -DremoteRepositories=<URL_to_your_maven_repo>
    -Dartifact=<group_id>:<artifact_id>:LATEST
    -Dpackaging=jar
    -Ddest=<target_dir>/<artifact_name>.jar


来源:https://stackoverflow.com/questions/1199244/how-do-i-find-the-latest-version-of-an-artifact-from-a-maven-repository

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