使用 Maven 离线构建项目,不使用 M2 repo,而是使用系统 jar
我有一个开源操作系统项目的需求,在nix环境下完全离线使用Maven。即它应该使用系统中可用的依赖项(可能在 /usr/share/ + 一些其他地方?)。 Maven 不应从互联网下载任何依赖项。
有没有解决方案可以实现这一目标?在系统中创建 M2 存储库并不是一个可行的解决方案。问题是文件系统是只读的。我们只能使用具有写入权限的临时文件夹(例如/tmp)。但是在临时位置维护存储库是一个糟糕的设计,不是吗? 换句话说,新安装的maven项目应该使用系统中现有的包(如果有的话)。如果软件包不存在,则应单独安装(通过软件包管理器),并且不应将其复制到 m2 存储库。
有什么已知的方法可以做到这一点吗?
感谢您的帮助!
PS:请注意,我不是在询问 -o 选项使其离线!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建自己的“镜像”存储库(/tmp 上实际 Maven 存储库的镜像)并要求 Maven 使用它而不是远程存储库。
示例:
http://maven.apache.org/guides/mini/guide -mirror-settings.html
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
我认为您可以创建一个本地 Maven 存储库(带有正确的文件夹树和 pom 文件),但使用符号链接到只写目录中的 jar。当然,这个解决方案并不比 Shamit Verma 的方法更容易,您必须编写一些代码。
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.
我们使用的方法如下。
我们决定将 m2 存储库存储在 /usr/share/maven-2/maven_home/m2_repo/ 中。这不是临时文件夹,需要管理员权限才能写入。但这不是问题,因为安装包也需要管理员权限。
我们已经对存储库中的 jar 进行了符号链接以指向系统级 jar。也就是说,我们维护了 Maven 存储库结构,但 jars 将它们符号链接到系统 jars。这意味着不会出现不必要的重复和空间浪费。我们仍然将 pom 文件保留在 repo 中。 pom 文件由 python 脚本重写以满足我们的需求。
此外,我们还引用了系统范围。例如,
对于系统范围,groupId:artifactId:version 组合是什么并不重要。它只是选择在
找到的 jarThe 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>