帮助我理解如何使带有非 Maven jar 依赖项的 Maven 项目可供其他人使用

发布于 2024-09-03 06:55:29 字数 738 浏览 5 评论 0原文

我正在学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独岁月 2024-09-10 06:55:29

那么,如何设置 ProjectA 的构建,以便有人可以下载 ProjectA.jar 并使用它,而无需为 ProjectB 和 ProjectC 安装 jar

假设 ProjectA 是一个 JAR,您可以创建一个可执行 JAR,将依赖项与 < a href="http://maven.apache.org/plugins/maven- assembly-plugin/" rel="nofollow noreferrer">Maven 程序集插件 (以及预定义的 jar-with-dependencies 描述符)或使用 Maven Shade 插件

如何设置构建,以便有人可以签出 ProjectA 并仅运行“mvn package”进行完整编译?

您必须将依赖项部署到可以通过 HTTP 读取的存储库,并在 pom.xml 中声明此存储库。 AFAIK,git-hub 不提供任何设施。但是任何具有 FTP 访问权限的网络托管服务(或者更好的是,scp)应该可以解决问题。如果您的项目是开源的,另一个选择是使用 Sonatype 的 OSS 存储库托管 服务。

以防万一,您可能需要阅读这篇博文但你不会学到更多的东西。

最简单的方法仍然是将 3 个项目组织为多模块 Maven 项目并构建所有模块。

此外,我应该如何处理修改后的 ProjectC 版本?

从模块化的角度来看(假设您找到了上述有关存储库部分的解决方案),将其作为单独的模块肯定是有意义的,特别是如果有人有机会在您的项目之外使用 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

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.

how do I set up the build such that someone could check out ProjectA and run only 'mvn package' for a full compile?

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.

Additionally, what should I do with my modified version of ProjectC?

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.

新一帅帅 2024-09-10 06:55:29

您必须从附加依赖项发布代码。两个选项:

  1. 使用 maven-shade-plugin 创建一个包含 B 和 C jar 的所有内容的 Maven 工件,并将其发布在您自己的 G/A/V 坐标下。
  2. 使用 maven-deploy-plugin 在您自己的 G/A/V 坐标下将 B 和 C 的副本发布到您的 forge,就像您发布自己的代码一样。不同的锻造厂有不同的政策;但如果你遵守 B 和 C 的许可,你应该没问题。

You have to publish the code from the additional dependencies. Two options:

  1. Use the maven-shade-plugin to create a maven artifact containing all the content of the B and C jars, and publish that under your own G/A/V coordinates.
  2. Publish copies of B and C under your own G/A/V coordinates using the maven-deploy-plugin to your forge just as you will publish your own code. Different forges have different policies; but if you abide by the licenses of B and C you should be OK.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文