帮助我理解如何使带有非 Maven jar 依赖项的 Maven 项目可供其他人使用
我正在学习 maven (以及 java 打包和分发),并正在制作一个新的 oss 项目作为练习。这是我的情况,当然都是java:
我的主要项目是ProjectA,基于maven,位于github存储库中。我还在 github 中创建了一个基于 Maven 的实用程序项目:ProjectB。 ProjectA 依赖于我进行了大量修改的项目,该项目最初来自基于 google-code ant 的存储库 ProjectC。
那么,我如何设置 ProjectA 的构建,以便有人可以下载 ProjectA.jar 并使用它,而无需安装 ProjectB 和 ProjectC 的 jar,以及如何设置构建,以便有人可以查看 ProjectA 并运行仅“mvn package”才能进行完整编译?
(另外,我应该如何处理我修改后的 ProjectC 版本?将类文件直接包含到 ProjectA 中,或者将项目分叉为可以用作 Maven 依赖项的东西?)
I'm in the process of learning maven (and java packaging & distribution) with a new oss project I'm making as practice. Here's my situation, all java of course:
My main project is ProjectA, maven-based in a github repository. I have also created one utility project, maven-based, in github: ProjectB. ProjectA depends on a project I have heavily modified that originally was from a google-code ant-based repository, ProjectC.
So, how do I set up the build for ProjectA such that someone can download ProjectA.jar and use it without needing to install jars for ProjectB and ProjectC, and also how do I set up the build such that someone could check out ProjectA and run only 'mvn package' for a full compile?
(Additionally, what should I do with my modified version of ProjectC? include the class files directly into ProjectA, or fork the project into something that could then be used by as a maven dependency?)
I've been reading around, links such as this SO question and this SO question, but I'm unclear how those relate to my particular circumstance. So, any help would be appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设 ProjectA 是一个 JAR,您可以创建一个可执行 JAR,将依赖项与 < a href="http://maven.apache.org/plugins/maven- assembly-plugin/" rel="nofollow noreferrer">Maven 程序集插件 (以及预定义的
jar-with-dependencies
描述符)或使用 Maven Shade 插件。您必须将依赖项部署到可以通过 HTTP 读取的存储库,并在 pom.xml 中声明此存储库。 AFAIK,git-hub 不提供任何设施。但是任何具有 FTP 访问权限的网络托管服务(或者更好的是,scp)应该可以解决问题。如果您的项目是开源的,另一个选择是使用 Sonatype 的 OSS 存储库托管 服务。
以防万一,您可能需要阅读这篇博文但你不会学到更多的东西。
最简单的方法仍然是将 3 个项目组织为多模块 Maven 项目并构建所有模块。
从模块化的角度来看(假设您找到了上述有关存储库部分的解决方案),将其作为单独的模块肯定是有意义的,特别是如果有人有机会在您的项目之外使用 ProjectC 的话。
Assuming ProjectA is a JAR, you can create an executable JAR that bundles the dependencies with the Maven Assembly Plugin (and the predefined
jar-with-dependencies
descriptor) or with the Maven Shade Plugin.You have to
deploy
the dependencies to a repository that can be read over HTTP and to declare this repository in your pom.xml. AFAIK, git-hub doesn't offer any facility for that. But any web hosting service with FTP access (or better, scp) should do the trick. If your project is open source, another option would be to use Sonatype's OSS Repository Hosting service.Just in case, you might want to read this blog post but you won't learn much more things.
The easiest would still be to organize the 3 projects as a multi-modules maven project and to build all modules.
From a modularization point of view (assuming you found a solution for the above part about repository), it would certainly make sense to have it as a separate module, especially if there is an opportunity someone can use ProjectC outside your project.
您必须从附加依赖项发布代码。两个选项:
You have to publish the code from the additional dependencies. Two options: