0

Short question:

Is there a way to install compiled jar files to another local repo other than the local repo of external dependencies?

Long question:

I want to compile my project using mvn clean install. Since the project uses some external dependencies, but maven will download those dependencies into my local repo.

This is good, but what I do not want is having the compiled jar files of my project also stored there, mixing with the others.

I want to find a way to keep all external dependencies in one local repo (e.g. C:\Repo) and then all my project jars are found in another local repo (e.g. D:\Repo) after compilation.

Vic
  • 21,473
  • 11
  • 76
  • 97
user1589188
  • 5,316
  • 17
  • 67
  • 130
  • I don't think you can, one instance of Maven will use one local repository directory. – Gimby Jul 15 '16 at 13:16
  • 1
    http://stackoverflow.com/questions/35451973/separate-local-download-and-install-repositories-using-maven – kuhajeyan Jul 15 '16 at 13:18
  • The install plugin accepts `-DlocalRepositoryPath` which would override the used repository. I imagine this is as close as you come, but it doesn't seem to help you all the way. – Magnilex Jul 15 '16 at 13:20
  • What are you trying to accomplish? Why would you like to separate them? What is your problem there? If you want to just compile/test your project you can simply achieve that by using `mvn clean package` or if you like to include integration tests `mvn clean verify` so nothing is installed into the local cache? – khmarbaise Jul 16 '16 at 10:01

1 Answers1

1

You want double <localrepository>, what is not possible for a single maven project.

  1. If you use settings you will add a new <localrepository> tag, you cannot add 2 <localrepository> tags.
  2. If you configure maven in your IDE i.e: Eclipse, you will have only a single text box to introduce a single localrepository location.

From DOCUMENTATION

Settings Details

Simple Values

Half of the top-level settings elements are simple values, representing a range of values which describe elements of the build system that are active full-time.
[...]

localRepository: This value is the path of this build system’s local repository. The default value is ${user.home}/.m2/repository. [...]

So, localRepository is a simple value, detailed in DTD (haven't found, someone?) of settings.xml, then does not matter how you configure maven, at the end, settings.xml file will be created somehow AND won't allow 2 localrepository tags.

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • I had a brainfart... I wonder if you could hack it with a symbolic link (which even modern Windows partitions support). – Gimby Jul 15 '16 at 13:20
  • @Gimby you know what DTD is? no hack for xml i guess, only one location will be allowed AFAIK – Jordi Castilla Jul 15 '16 at 13:22
  • Thanks. How about some hacky way? Like doing two passes? I am thinking if there is a way to stop maven from installing my project files to my local repo, then I can first compile normally (without storing my project files). Second pass set my local repo as the remote repo using file:// and change my local repo to another folder, allowing maven to install my project files this time. – user1589188 Jul 15 '16 at 13:33
  • 2
    @user1589188 Maven will then download and install all dependencies in the local repo of the second pass, not only your project artifacts. – Gimby Jul 15 '16 at 14:04
  • 1
    @user1589188 They'd just see a demand from one person without any explanation at all. – Gimby Jul 18 '16 at 07:03