I have a requirement for a project in an open source operating system, to use Maven completely offline under nix environment. i.e. it should use the dependencies available in the system (probably at /usr/share/ + few other places?). Maven should not download any dependency from internet.
Is there a solution to achieve this? Creating the M2 repo in the system is not a viable solution. The issue is that the file system is read-only. We can only work on a temporary folder (/tmp for example) with write access. But maintaining a repo at a temporary location is a bad design, isn’t it?
Saying it another way, the new to be installed maven project should use the existing packages in the system, if available. If packages does not exist, it should get installed separately ( via the package manager), and should not be copied to the m2 repo.
Is there any known way to do this?
Thanks for the help!
PS: Please note that I’m not asking about -o option to take it offline!
The approach we used is the following.
We’ve taken a decision to store m2 repo at /usr/share/maven-2/maven_home/m2_repo/. This isn’t a temporary folder, and needs admin rights to write. But that isn’t a problem since the installing packages also needs admin privileges.
We’ve symlinked the jars in the repo to point to system-level jars. i.e. we maintained the maven repository structure, but the jars were symlinked them to the system-jars. This means there’s no unnecessary duplication and waste of space. We still keep the pom files in repo. The pom files were rewritten by a python script to match our needs.
Further, we refered dependencies with the system scope. For example,
With system scope, it doesn’t matter what the groupId:artifactId:version combination. It just picks the jar it find at
<systemPath>