开发者

Building projects with Maven offline without using M2 repo but using system jars

I have a requirement for 开发者_C百科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!


You can create your own "mirror" repository (Mirror of actual Maven repository on /tmp) and ask Maven to use that instead of remote repository.

Example :

http://maven.apache.org/guides/mini/guide-mirror-settings.html


I think you can create a local maven repository (with right folders tree and pom files), but use symbol links to jars in your write-only directory. Sure this solution is not easier then Shamit Verma's approach and you must write some code.


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,

<dependency>
  <groupId>groupId</groupId>
  <artifactId>artifactId</artifactId>
  <version>666</version>
  <scope>system</scope>
  <systemPath>/usr/share/maven-core/lib/maven-core.jar</systemPath>
</dependency>

With system scope, it doesn't matter what the groupId:artifactId:version combination. It just picks the jar it find at <systemPath>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜