2

Simple Maven clarification; I hope this will be easy to answer from an experienced Maven developer.

I have two projects called mycompany-x and mycompany-y. mycompany-x is listed as a dependency of mycompany-y, and each has version 1.0-SNAPHSOT. Our Maven build is deployed to an internal Maven repository by a continuous build server. Snapshots of each are shared between developers via this server. We are using Maven 3.

At any given time, when I run the install goal of mycompany-y, there may be two jars in the repository for mycompany-x: one, labeled 1.0-SNAPSHOT, that is the result of a local build; the second, labeled 1.0-, downloaded as a resolution to the 1.0-SNAPHSOT from our Maven repository. This creates an obvious ambiguity when mycompany-y attempts to resolve 1.0-SNAPSHOT of mycompany-x; one which I am quite certain the Maven community has an explicit policy to resolve (although it is not clear in the docs).

In the following scenarios, which jar (local or remote) is included in the classpath of the build?

  1. Run mvn install on mycompany-x and mycompany-y.
  2. Run mvn install on mycompany-y, without having previously run install on mycompany-x.
  3. Run mvn install on mycompany-y, having recently built mycompany-x (and no later version in the remote repository).
  4. Run mvn install on mycompany-y, having recently built mycompany-x (but with a more recent version in the remote repository).

Note: Maven: How to ensure timestamped versions of snapshots are used in classpath? references a published algorithm, which I can't seem to find anywhere. I would accept a link there as a fine answer.

Community
  • 1
  • 1
Peter Bratton
  • 6,302
  • 6
  • 39
  • 61

1 Answers1

3

Here is the link I referred to in the other post - Maven Dependency Resolution - A Repository Perspective.

Note that this resolution (unfortunately) has shifted over time, even with the 3.0.x series in Maven. See the Maven release notes for the following issues:

[MNG-4987] - [regression] LATEST, RELEASE or SNAPSHOT version picked from wrong repository when resolution order does not match timestamp order [MNG-4592] - Snapshot artifacts that could not be downloaded due to communication problems are "blacklisted" for a day by default. [MNG-4751] - Snapshot version not resolved for version range

The configuration values for SNAPSHOT resolution also affect things.

Here's an example of another poster dealing with SNAPSHOT

Alas, even if you figure it out, you have to explain it all to the rest of the devs on the team.

How we solved this: Instead of using SNAPSHOT dependencies on the CI, we only allow projects built on the CI to declare fixed dependencies. We use the Maven Release Plugin to make production of a release (non-SNAPSHOT) a single-click affair. Developers can (and should) have SNAPSHOTs referring to each other locally, but keep the remote repository completely out of it.

Community
  • 1
  • 1
Will Iverson
  • 2,009
  • 12
  • 22