0

Forgive my ignorance here, as I'm new to maven. I have a Remote Repository that my project pom is using to download dependencies from. A general structure of my pom.xml is like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MVNProject</groupId>
    <artifactId>MVNProject</artifactId>
    <version>0.0.1</version>
    <packaging>war</packaging>
        <dependency>
            <groupId>org.scala-lang.modules</groupId>
            <artifactId>scala-parser-combinators_2.11</artifactId>
            <version>1.0.1</version>
        </dependency>
    </dependencies>
</project>

Now I know that if I have to get a new version of the dependency scala-parser-combinators I just have to specify the new version. Something like this:

<dependency>
    <groupId>org.scala-lang.modules</groupId>
    <artifactId>scala-parser-combinators_2.11</artifactId>
    <version>1.0.1</version>
</dependency>

But what I would like to do is, without making any change to pom.xml I'd like to replace my old jar with the upgraded jar in my remote repository(which I'm able to do).

So what I'd like to know is whether there is a way to specify in pom to take whatever version is available in the remote repository for a particular artifact i.e., something like this(and this is just a guess):

<dependency>
    <groupId>org.scala-lang.modules</groupId>
    <artifactId>scala-parser-combinators_2.11</artifactId>
    <version>${CurrentVersion}</version>
</dependency>

Some guidance would be very much appreciated.

Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
Marek
  • 245
  • 1
  • 4
  • 15
  • Would you like to know how to define ${CurrentVersion} with concrete value? – sharon182 Mar 07 '18 at 06:43
  • Possible duplicate of [How do I tell Maven to use the latest version of a dependency?](https://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency) – Gyanendra Dwivedi Mar 07 '18 at 06:59

2 Answers2

0

If you are using maven2, then using LATEST or RELEASE value in version tag can solve the dependency updation automatically. Albeit , this solution will not work in maven3 (it is deprecated).

If you are using maven3, then you have to update the settings.xml a bit. The snapshots repository will get an addition updatePolicy tag. Something like this:-

<repositories>
    <repository>
        <id>you-snapshots</id>
        <url>http://host/nexus/repos/snapshots</url>
        <snapshots>
            <updatePolicy>always</updatePolicy>
        </snapshots>
        <releases>
            <updatePolicy>always</updatePolicy>
        </releases>
    </repository>
</repositories>

Also , There is a Versions plugin for Maven which allows you to update your pom to the latest greatest SNAPSHOTS in visible repositories. It does this by inspecting your pom and comparing against remote repositories and then modifying as required.

It is a useful tool but I would definitely like to see an equivalent to the deprecated LATEST option. I find this kind of dependency particularly useful in continuous integration scenarios.

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29
  • Luckily, for me I'm using maven2. Correct me if I'm wrong, but are you suggesting that if I put ` org.scala-lang.modules scala-parser-combinators_2.11 RELEASE ` in my pom, it will take whatever version is currently available in remote repository? – Marek Mar 07 '18 at 06:58
  • Yes, I meant that. – Manmohan_singh Mar 07 '18 at 08:17
0

Some things to notice:

  • You should not delete a specific release version of an artifact from a remote repository and replace it, like having 1.0.1 in your remote repository, removing it and uploading a different artifact under 1.0.1 again. Maven caches release versions in the local repository, so you will never know which artifact you get.
  • If you have a newer version, give it a newer version number (like 1.0.2).
  • Now the way to go is not to use RELEASE or LATEST, but to use the versions plugin to update your dependencies (like versions:use-latest-releases).
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142