Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all Versions of an Artifact via Command Line

Including all versions installed to ~/.m2, and deployed to maven or an artifact repository like artifactory.

For example, if I type something like this make believe command:

mvn ver:show-all -DartifactId=myProject -DallowSnapshots=true

I hope to see some output listing available versions:

myProject ->
  0.9
  1.0.1
  1.1-branchA-SNAPSHOT
  1.1-branchB-SNAPSHOT
  1.1-branchC-SNAPSHOT

Is there a maven plugin which does this today?

like image 608
Chris Betti Avatar asked Nov 20 '15 19:11

Chris Betti


People also ask

What is artifact version?

Last modified: 17 March 2022. An artifact is an assembly of your project assets that you put together to test, deploy, or distribute your software solution or its part.

Where does Maven look for artifacts?

The first place that Maven looks for artifacts is in the local repository, which is the local cache where Maven stores all of the artifacts it has downloaded or found elsewhere. The default location of the local repository is the . m2/repository/ directory under the user's home directory.


1 Answers

What you can do is look at Maven Repository Metadata Model. It's basically and XML file that you can download and parse. For example, to know all the versions of Google Guice available in Maven Central download repository metadata, available at https://repo1.maven.org/maven2/com/google/inject/guice/maven-metadata.xml and look at its content:

<metadata>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <versioning>
    <latest>4.2.2</latest>
    <release>4.2.2</release>
    <versions>
      <version>1.0</version>
      <version>2.0</version>
      <version>2.0-no_aop</version>
      <version>3.0-rc2</version>
      <version>3.0-rc3</version>
      <version>3.0</version>
      <version>4.0-beta</version>
      <version>4.0-beta4</version>
      <version>4.0-beta5</version>
      <version>4.0</version>
      <version>4.1.0</version>
      <version>4.2.0</version>
      <version>4.2.1</version>
      <version>4.2.2</version>
    </versions>
    <lastUpdated>20181029173633</lastUpdated>
  </versioning>
</metadata>

You'll see all the versions!

Though, it's not a 100% complete solution:

  • There may be newer (other) version(s) in other repositories. E.g. if one syncs JARs from Bintray to Maven Central Bintray can contain the JARs not available in Central. Though, they seem to be the same for Guice.
  • There may be no maven-metadata.xml. E.g. if you're using JitPack or repos hosted on S3.
like image 55
madhead - StandWithUkraine Avatar answered Dec 07 '22 02:12

madhead - StandWithUkraine