3

i have following requirement. i need to download the latest version of artifact from custom nexus repository rather than snapshot repository.

please suggest

Thanks.

user2315104
  • 2,378
  • 7
  • 35
  • 54
  • Which version of maven are you using ? – Saif Asif May 07 '14 at 10:12
  • Possible duplicate of [Using the Nexus rest API to get latest artifact version for given groupid/artifactId](https://stackoverflow.com/questions/7911620/using-the-nexus-rest-api-to-get-latest-artifact-version-for-given-groupid-artifa) – TT-- Jun 17 '19 at 17:49

2 Answers2

1

To get the latest version of any artifact, just omit the <version> tag from the dependency. This way maven will always fetch the latest version of this artifact from the remote repo.

Warning: Keep in mind that this is not the preferred way to handle dependencies nor it is the proper flow of dependency management. By keeping the version number open ended, there is a very high probability that your project may fetch a particular version of any library that is now not backward compatible and may break your functionality in the project. It is, therefore, always recommended to specify a particular version number of all artifacts that are required for any application and when updating any library version, one should properly test it.

EDIT

For maven3 you can use the facility of an open ended version tag. Something like this

<version>[1.12.4,)</version>

Take a look into this page for further details about version ranges

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
  • 1
    Maven 3 does not allow to omit the version number. – Absurd-Mind May 07 '14 at 10:10
  • True, Updated answer for both maven3 and maven2 – Saif Asif May 07 '14 at 10:14
  • Don't use version ranges, cause you build is not reproducible anymore. – khmarbaise May 07 '14 at 11:21
  • but lets say, the said artifact is present in many repos like snapshot,releases, abc then in that case from which repo it will pick the latest version if i don't mention the version tag in dependency ?? – user2315104 May 07 '14 at 18:52
  • @user2315104 That depends on your `settings.xml` and how you have defined repositories. By default, the repos are always searched through in the order they are defined in your `pom.xml/settings.xml`. – Saif Asif May 08 '14 at 07:38
1

According to this issue: https://issues.apache.org/jira/browse/MNG-3092 snapshots cannot be excluded (at least until this is fixed).

Todor Kolev
  • 1,432
  • 1
  • 16
  • 33