Alternate local repository: a repository which looks like your local repo but is read only. So it is kind of global repository e.g. repo.maven.apache.org or your organization hosted repository (which you can read-only), but resides either on network or on your computer only.
I came across many use cases when an alternate local repo can help in building the project in super fast manner. I will list out the benefits here:
- You may be moving to another branch of the project: You may start from scratch where the local repository will be created and populated by fetching the artifact from remote repository. But if you have existing repository for different branch of the project, it may have many artifacts which were unchanged for across the project. So you may want to use that repository as alternate local repo, so that the requests of artifacts could be satisfied locally and you can build the project in faster manner.
- NFS mounted repository: It is possible that you have built the project in one machine A (say windows) but now want to build on linux machine B, so not instead of fetching the artifacts from remote repo, you can mount box A as nfs mounted disk on another machine B and use the local repo of A as the alternate repo of B. Since the artifacts will be present in machine A, the build time will be lesser.
- Reproducing issue on build machine: It is possible that you are building on build machine which is not owned by you. Since it is a build machine, artifacts are very likely to be there.
- You are on ancient build but want to clean up:
- You want to clean up your local repo in smart manner:
- You may want to share your repo with a colleague who is on old build and co-incidently you have the repo for it.
I am sure there would be many reasons of having alternate repo.
So here is the way. I modified the code of SimpleLocalRepositoryManager.java which exists inside aether project of maven.
I have done changes in aether-1.0.2.v20150114.
Once you have configured above jar in the maven lib directory, all you need to set NETWORKREPO environment variable for example
export NETWORKREPO=/data1/builds/repo/oldBackup (in unix)
set NETWORKREPO=c:\repo\oldBackup (in windows)
where oldBackup is the network local repository (will be treated as read-only).
You can also mount network shared directory in your machine and use that by setting it as NETWORKREPO.