Question

UPDATE: Simplifying my question - I have a module mod1 which is used as dependency in module mod2. I would like to make sure that mod2 always utilizes the latest version snapshot of mod1. How can I achieve that in Maven?

================

I have two modules where one module is used as dependency in another module. How can I make sure that the latest snapshot of mod1 always gets utilized in mod2? Both the modules are mentioned in the parent pom as following -

<modules>
   <module>mod1</module>
   <module>mod2</module>
</modules> 

I have a release version of mod1 on remote maven repo (version 1.0). Now, in my build when there is a code chanage in mod1, it gets built as 1.1-SNAPSHOT (not deployed on remote repo). How can I make sure that mod2 utilizes this (latest) snapshot version? If mod1 source was changed then the new version 1.1-SNAPSHOT needs to be utilized in mod2 and if mod1 did not have source change then the existing latest version of 1.1 need to be utilized in mod2. Could anyone suggest how to always use latest snapshot/release here? I tried following in pom.xml for mod2 -

<dependency>
   <groupId>com.test</groupId>
   <artifactId>mod2</artifactId>
   <version>LATEST</version>
</dependency>

However, that always resolves to the release version 1.0 and never resolves to 1.1-SNAPSHOT, which is in local repo. How can I make sure that the latest snapshot gets utilized? Will appreciate any suggestion.

Était-ce utile?

La solution 2

I did find the solution. Under dependency, adding following worked -

<version>[1.0-SNAPSHOT,)</version>

If snapshot wasn't present, it picked up the latest release, which is what I needed.

Autres conseils

The version -SNAPSHOT already includes the notion of "latest".

So our release cycle needs to look like this:

Before you start, you have: mod1 version is 1.0-SNAPSHOT, mod2 version is 1.1-SNAPSHOT and it depends on mod1:1.0-SNAPSHOT

Now you want to release. To do so, you remove -SNAPSHOT everywhere, build & deploy.

After the deployment, you bump the versions:

mod1 version is now 1.1-SNAPSHOT, mod2 version is 1.2-SNAPSHOT and it depends on mod1:1.1-SNAPSHOT

You will never have the situation that a snapshot version of mod2 depends on a release version of mod1.

Typically, modules within the same project use the same version, by not specifying a version in the module at all. In that case Maven will fall back on the parent's version.

With that setup, mod2/pom.xml can have something like this:

    <dependency>
        <groupId>com.test</groupId>
        <artifactId>mod1</artifactId>
        <version>${project.version}</version>
    </dependency>

In this situation you should not need to install mod1 to your local repository at all.

Just run your mvn commands from the top level directory and mod2 will be able to resolve mod1 without trouble. Eclipse and Idea will also handle this setup correctly.

If you have a specific use-case where you need to install mod1, or you need the two modules to have separate version numbers, please explain that, as it might help answer the question for you better.

Lastly, you might find the Versions plugin useful. It can manage your project, plugin, and dependency versions, upgrading them as necessary.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top