2

I have a machine in which multiple parallel maven execution happen. Each execution executes the below command in a separate workspace directory

mvn -f main/pom.xml clean package -DskipTests -T 6

Can someone let me know should I use a separate maven local repo path (-Dmaven.repo.local=$MAVEN_REPO) for each execution or I can use a common .m2 directory for all parallel runs? What is the common practice followed?

  • Maven Version 3.5
  • Java 8
tuk
  • 5,941
  • 14
  • 79
  • 162

3 Answers3

1

You cannot share a local repository between executions. They are not implemented to tolerate multiple concurrent processes accessing them. You can and should run a local caching repository manager in between your processes and repositories on the internet. That can be shared.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • So are you suggesting I should not use a same folder ( for `maven.repo.local` ) for concurrent executions? I do not have a requirement where one of my project require an artifact created by another project. Can you also explain what do you mean by local cachine repository manger ? Something like Jfrog, nexus, etc ? – tuk May 26 '19 at 17:13
  • The local caching repository is your machine which run the project. It will store dependencies in a certain destination for maven to use them when building your project. In case one of the dependencies is not available locally maven will try to fetch it from remote (Maven central, jcenter or binary manager tools such as Artifactory (JFrog), Nexus etc.) – Aviza Jul 08 '19 at 22:54
0

I will start by saying that it is possible to set multiple local repositories or a local repository for each project. Indeed, the way to do it is by setting each project with its own settings.xml. Each settings.xml will have a localRepository tag pointing to a different path. The Dmaven.repo.local=/path/to/repo flag to run the project points the execution to the settings.xml with the specific local repository.

Usually, it is not needed at all. Maven can handle parallel executions and having a central local repository for all your projects (where all artifacts are installed and download) can facilitate their handling and will not short the building time. The only way it can effect you is if one of your projects require artifact created by another - but this should not be handled by multiple local repositories either.

Aviza
  • 142
  • 1
  • 7
  • Are you saying I can specify a common folder in `maven.repo.local` for all concurrent maven execution like `mvn -f main/pom.xml clean package -DskipTests -T 6`)? I don't have a requirement where one of my projects requires artifact created by another. – tuk May 26 '19 at 17:19
  • Yes. You don't need to use this flag at all. You will just have a single local repository where all artifacts will be stored on the default .m2. – Aviza May 26 '19 at 17:51
0

This has been discsussed in maven user mailing list also. Summary of the discussion

Hello,

It is the other way around, there might be situations where one job relies on the installed artifacts from the other, in this case you would need a shared Repo. It is however bad style. In all other cases you can use a executor- or even workspace-local local repository if you have enough space.

The advantage of avoiding concurrent access is that you get less influences from one job to the other (especially if you work with snapshots or multiple different upstream artifacts with same version in different Repos) and that there is no concurrent downloads (which in itself sometimes leads to checksum errors).

Gruss Bernd

tuk
  • 5,941
  • 14
  • 79
  • 162