Sean Mc
Sean Mc

Reputation: 71

How to specify different local maven repositories for different projects in their pom files?

I have one .m2 repository. I have 2 projects. JavaProject and HibernateProject. I want them to reference different .m2 repositories. How is this done?

Upvotes: 0

Views: 753

Answers (1)

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24483

You can't specify the local repository location in your POM file. If you were able to, it would break Maven: the whole point is to be able to distribute your POM file to other people and have the code just work. If the POM file contains a reference to ~seanmc/localrepos/hibernateproject then it's not going to work on my machine.

The place where you specify the local repository is in your settings.xml. Typically you have one global settings and one user settings. You can pass the -s flag to Maven to specify a settings file to use. So you could make a settings file for each project. Inside the settings file (reference) you'll want a <localRepository> tag with the path to the local Maven repository you want to use.

Be aware, though, that doing this is contrary to Maven's design. Probably, you have a bug in your architecture or your thinking.

Upvotes: 2

Related Questions