Use a local folder as maven repository

  • 1 min read
  • Tags: 
  • java
  • mvn

Use a local folder as you maven repository

When I have multiple steps in my CI, to be sure to not download multiple times maven repositories, I use the "npm" way.

So how to end up with a local .mvn folder containing all you dependancies ?

.gitignore

First, you want to push some files to git but not dependancies:

# .gitignore

.mvn/repository

Then in you need these files:

# .mvn/maven.config
--settings

./.mvn/local-settings.xml
# .mvn/local-settings.xml

<!--
 This local settings is used to force maven to use a local repo instead of ~/.m2.
 So that when running e2e tests, the docker image can use the already downloaded libs.
 -->
<settings>
    <localRepository>.mvn/repository</localRepository>
</settings>

That's all.

Now you can share some parameter with your colleagues, from the local-settings.xml file.

And for example you can run maven commands in a local docker with a volume at ./ and have maven dependancies shared.