Daniel Kaplan
Daniel Kaplan

Reputation: 67320

What order does maven find its dependencies?

I've got a multi module project that uses war overlays and we have a continuous integration server that often deploys the snapshots. I have questions like, if I do a mvn compile right after the CI server does a deploy of it, will my build get my local changes or the CI changes? How do I force my project to use a war overlay I've changed locally? I figure an install could do that, but what if the CI server builds a version with a newer timestamp. Which one will it use?

This is just a few of the many questions I have and I can't find an authoritative answer on the maven documentation. But, even if I could I'd probably come right back here and ask someone to explain the documentation better :P So, I ask, what is the order/logic maven uses to find it's dependencies?

Upvotes: 3

Views: 799

Answers (3)

Rajkumar Singh
Rajkumar Singh

Reputation: 1527

e know that a project's dependencies are declared in pom.xml. Apache Maven uses concept of repository to hold JAR files. There are two kinds of repository, local repository and remote repository. You can define this in settings.xml on maven/conf directory or pom.xml itself. When we kick off Maven build process by executing mvn install command, it first search for dependency JAR in local repository, if it found there it uses, otherwise it goes to remote repository to download corresponding version of JAR file and stores into local repo as well. There is one more thing, which is worth remember is type of dependency. If you have included a SNAPSHOT JAR e.g. 1.2-SNAPSOT as part of your dependency, opposite to regular stable version 1.2

Upvotes: 0

ceilfors
ceilfors

Reputation: 2727

As far as Maven concerns, the artifact generated from your war overlays will just be yet another artifact.

if I do a mvn compile right after the CI server does a deploy of it, will my build get my local changes or the CI changes?

This will be depending on your snapshots updatePolicy in your settings file. It is by default set to daily. More details here: http://maven.apache.org/settings.html#Repositories

How do I force my project to use a war overlay I've changed locally?

Change the snapshots updatePolicy to never (or -o option, suggested by @matsev). This means the SNAPSHOT dependencies that you are using will always be the local version. To force grab the latest from the repository one with this updatePolicy, use the -U option.

I figure an install could do that, but what if the CI server builds a version with a newer timestamp. Which one will it use?

Yes, install will basically deploy your artifact to your local repository (.m2 folder). Then, depending on the updatePolicy, maven will compare the locally deployed artifact and the repository artifact. If updatePolicy is set to always, maven will always grab the repository one if it has a newer timestamp. The same goes to daily, except that maven will only compare the timestamp daily.

I can't find an authoritative answer on the maven documentation.

Totally agree. Sadly, I understand most of these partly through experience.

Upvotes: 3

matsev
matsev

Reputation: 33749

You can use the -o (--offline) option to force Maven to use your local files, e.g.

mvn -o clean install 

See Maven Command Line Options for reference (or simply execute mvn -h).

Upvotes: 1

Related Questions