1

Observation: I was testing how Maven retrieves artifacts when building artifacts using mvn package (or) mvn install command. I noticed that Maven was connecting to the Internet to get the dependencies every single time. There was not much time gap (maybe around 1 or 2 minutes) between successive runs as well.

Question: Therefore, if Maven connects to Internet (or the repository provided in my settings.xml) every time by default, why do they have a separate attribute that can force update (The -U attribute which is used like this: mvn install -U of a snapshot from the repo? What is the factor that governs/decides between connecting to an external repo or using local repo for retrieving dependencies?

Reference: (Please refer http://www.sonatype.com/node/158?file=books/maven-definitive-guide.pdf Page 93 to know more about this attribute). The reference just explains about the attribute but the governing principle behind it is not explained.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
n7rider
  • 477
  • 3
  • 12
  • Hint: [Maven: The Complete Reference](http://books.sonatype.com/mvnref-book//reference/index.html) is also available in HTML. – Gerold Broser Apr 17 '16 at 11:03
  • It depends on other settings, too. See [maven snapshot updates](http://stackoverflow.com/questions/2148111/maven-snapshot-updates). – Gerold Broser Apr 17 '16 at 11:11
  • Thanks! The documentations mention that updating once per day is the default norm. (http://maven.apache.org/settings.html#Repositories). That seems to be the answer for the question. – n7rider Apr 18 '16 at 16:11

1 Answers1

1

I find -U/--update-snapshots to be a helpful hint at best, and seems to be different in Maven2 vs. Maven3.

Even with release artifacts, maven3 sometimes requires it to update the artifacts on both specific versions and version ranges. Other times, my local repository gets updated correctly. Go figure.

Do you know what artifacts Maven is checking/receiving when not specifying -U? I think, but have not confirmed, that Maven is checking/downloading plugins, which may have different rules than the dependencies in your POM.

The only way to truly convince Maven to not check outside the local repo is to use -O/--offline and then it'll use whatever you have.

Scott Sosna
  • 1,443
  • 1
  • 8
  • 8
  • I was using standard well known dependencies like FreeMarker, Commons-lang, Spark, Commons-codec etc. I don't think none of these are getting hourly updates for Maven to go and check online (or the central repository) instead of using my local repo. Yeah -o (offline) helps when I specifically want to be offline. It seems -U and -o are the polar opposites. So if we don't specify any of these, I wonder how Maven decides whether to use local repository's artifacts or go fetch artifacts again. – n7rider Apr 18 '16 at 16:06
  • I've never completely understood it either, probably would require digging into the Maven code itself. – Scott Sosna Apr 19 '16 at 01:40