6

I know how to do it for an external repository but not for my local repository, since I don't have a <repository> for my local repository in my settings.xml.

I use snapshot versions for my sub-projects, so when I re-build the parent project I want maven to get all the sub-projects snapshot versions from my local repository not only once a day (which seems to be what happens by default) but always.

rapt
  • 11,810
  • 35
  • 103
  • 145
  • What do you mean `once a day`? If you have your sub-projects artifacts in your local repository, only the latest snapshot version of each of them will be used. – Andrew Logvinov Jan 16 '13 at 18:27
  • Right now when I re-build the parent project, it will NOT try to re-build the jars for the sub-projects (although I changed the sub-projects code). Instead it rebuilds the parent jar from the old sub jars. All those projects (both parent and subs) are snapshots `1.0-SNAPSHOT`. Also, I simply defined my sub-projects as dependencies of the parent project... By "once a day" I was referring to what I read here http://stackoverflow.com/a/5907727/784980 – rapt Jan 16 '13 at 19:03

3 Answers3

9

If I'm understanding your comment, I think @FrVaBe may have the correct answer. When you change code for a child project on your development machine, it's up to you to rebuild the snapshot and get it into your local artifact repo (via mvn install) so it's available for the parent project to use.

If, however, you want your parent project build to pull in changes made by your teammates and published to the corporate remote repository more often than once per day, read on.

Here is a summary of how Maven central (and kin), remote repositories (e.g a company instance of Nexus or Artifactory) and your local repository work together. If you always want the latest version of snapshots to download on every build, go into your settings.xml file, find <snapshot> repository containing the snapshot you want, and change the <updatePolicy> value to "always". Personally I rarely do this, I simply add the '-U' option to my mvn command line when I want to ensure I have the latest version of a snapshot from my remote repo.

Community
  • 1
  • 1
user944849
  • 14,524
  • 2
  • 61
  • 83
  • 1
    `-U` is the better option, instead of configuring globally in the pom then forgetting about it only to run around in circles debugging an issue it caused. – raffian Dec 02 '15 at 22:32
3

There is no update policy for the local repository!

The local repository is just a bunch of files. When you install to your local repository your local projects already reference the artifacts directly. There is no update that needs to be performed except that maybe your IDE needs to be refreshed to pickup the newer files.

In this manner you can build local snapshots all day long with no versioning headaches, no updates required and no old artifacts left hanging around afterwards. Nice and clean but not so obvious if you're new to Maven and still getting to grips with all these repositories and their fancy update mechanisms.

Josh
  • 4,894
  • 6
  • 34
  • 42
2

I think you missunderstood something. Maven will always take the latest/newest SNAPSHOT from your local respository. But in your project setup (Project Inheritance) you need to build the sub projects on their own if you changed something.

An automatical build of the sub project only happens on a Project Aggregation layout.

The difference is explained in the Project Inheritance vs Project Aggregation section of the documentation.

FrVaBe
  • 47,963
  • 16
  • 124
  • 157