27

I've refactored all repository configuration out of my various projects into a parent pom that I've created for the specific purpose of having a single point of configuration for stuff like repo's and distribution management. This is supposed to be best practice as I understand it. In deployed my parent pom to the nexus server, and then tried to run my child projects. They can't find my parent pom . . . this kind of makes sense to me since, wihtout the parent pom they don't know about the nexus repo . . . seems like a chicken and egg kind of thing? Am I missing something obvious?

chad
  • 7,369
  • 6
  • 37
  • 56

2 Answers2

13

It's true that your project needs to know where to find the repositories to download its dependencies. But before going to external repositories, Maven will check your local repository to see if the artifacts it needs are in there. Does your local repository contain the parent pom? If not, you can add it by running

mvn install

on the parent pom. The problem may have been caused by deploying the parent pom directly to Nexus, bypassing your local one. You can avoid this in future by deploying using

mvn deploy

This will first install the artifact locally, and then deploy it to the external repository (Nexus, in your case). More details here: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

If you're in a situation whereby your parent pom is built and deployed by others, this won't help. You can either specify the repositories in your project's pom, or in your local settings.xml. A common approach is to expect all developers to include a repository definition in their local settings.xml which points to your Nexus repository, using it as a mirror for all other repositories. You can then configure each external repository you need in Nexus, and let it retrieve any dependencies you need for you. I'm not familiar with Nexus, but more details on mirroring can be found here: http://maven.apache.org/guides/mini/guide-mirror-settings.html

Conan
  • 2,288
  • 1
  • 28
  • 42
  • Thanks, this helps. I was hoping I'd find a solution that meant a developer could simply check out the project, and build and everything would just work. This "design imperitive" makes the settings.xml thing a bit annoying, but not bad ;) The problem is that the parent pom, in the scm structure, resides above many projects. A developer on a specific proj, doesn't want to checkout at the height of the parent pom . . . maybe some scm trickery is in order. – chad Jan 06 '12 at 15:16
  • Sure, I've come across that problem myself. It is possible to put the parent pom elsewhere, rather than at the top of the svn tree, and define the sub-modules in another pom that is at the top. The parent-child relationship has two aspects in Maven; defining a parent allows inheritance of configuration, and defining modules allows builds to be aggregated. The two don't have to go together though - you can put the parent project elsewhere, and use a new pom at the top of your svn tree, so that the parent can be checked out and built on its own. – Conan Jan 07 '12 at 19:01
10

You must maintain the repositories definitions for each child (maven module), this is main best practice in a build process: "Make the build portable".

Any developer/system should be able to build any module without source dependencies to the parent or other modules, only with the repository reference.

alexfdz
  • 435
  • 4
  • 5