Vibhav Agrawal
Vibhav Agrawal

Reputation: 141

Setting Project specific maven repository

I have multiple projects. I want to create different maven repository paths for each project. Means, each project should point to different folder as maven repository (by default C:/Users/USERNAME/.m2 is used as repo). I know that this may increase the download and same files if used in multiple projects will be downloaded/kept multiple times. But i want to separate out the repository for different projects so that i can bundle the repository along with my project's source code to be shared to the other person. I simply dont want to share my whole m2 repository (of size 2 gb) for a very small project sized 50 mb.

Regards,

Vibhav

Upvotes: 10

Views: 7919

Answers (4)

Javier Moreno
Javier Moreno

Reputation: 1

My solution using Eclipse and Maven is to create new workspace, maven repository and settings.xml replacing the default .m2 repository path.

your new settings.xml

Then, try in Eclipse: Preferences>User Settings and browse your settings.xml

replace the User Settings file

Upvotes: 0

Vibhav Agrawal
Vibhav Agrawal

Reputation: 141

Thanks everyone for your comments.

I finally did the following:

  1. Setup each project as a separate workspace in eclipse
  2. Created a separate apache maven folder for each project (actually duplicating the maven home even though i am using same version of maven)
  3. From eclipse workspace, I pointed out the appropriate maven home
  4. configured the repository path (localRepository) in MAVEN_HOME/conf/settings.xml file from default ~./m2/repository to something like MAVEN_HOME/repo

This way, I could get separate maven repositories for each project (or I should say workspace).

Thanks, Vibhav Agrawal

Upvotes: 2

Mark O'Connor
Mark O'Connor

Reputation: 77951

See the following answer:

Prevent Jenkins from Installing Artifact to Local Maven Repository

In a nutshell use a settings file for each build. Enables you to control both the local repository used for that project, but also other settings like repositories and build profiles.

Upvotes: 0

Alex Gitelman
Alex Gitelman

Reputation: 24722

You can specify repository location via command line option -Dmaven.repo.local=

I'd have just put a wrapper script to start maven in the project location and specified repository in it (probably pointing to location inside the project for your use case).

Upvotes: 4

Related Questions