如何设置maven框架顶级pom

发布于 2024-12-26 18:37:31 字数 1058 浏览 4 评论 0原文

我刚刚完成将我们的一个内部框架项目从 ant 转换为 Maven。 Maven 构建运行良好,并且可以毫无问题地部署到我们的存储库。

问题是当其他项目尝试使用该框架时,它不起作用。唯一下载的是顶级框架pom。

我尝试向一个或多个不同模块添加一些依赖项,但无论添加哪一个,都会出现循环依赖错误。我还尝试创建第二个顶级 pom 文件,其中没有模块和一些依赖项来覆盖存储库管理器中的文件。这会导致下载一些依赖项,但随后 Maven 构建将挂在随机位置。基于Windows任务管理器,它看起来像是处于无限循环中。所以第二个 pom 文件似乎不是答案(或者我做错了)。

我的框架 pom 文件看起来像这样:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>framework_snt</groupId>
  <artifactId>SFP</artifactId>
  <packaging>pom</packaging>
  <name>SFP framework</name>
  <version>6.3</version>

  <modules>
.... 50+ modules here
  </modules>

然后是顶级 pom 的常用属性、依赖管理和插件管理条目。

在消费模块中,我只有以下内容:

<dependency>
  <groupId>framework_snt</groupId>
  <artifactId>SFP</artifactId>
  <version>6.3</version>
  <type>pom</type>
</dependency>

这是在顶级 pom 中,因此所有子模块都可以访问框架库,以使开发人员更容易。

如何设置才能使我的消费项目下载所有依赖的 jar 文件?

I just finished converting one of our in-house framework projects from ant to maven. The maven build runs fine, and deploys to our repository with no issues.

The problem is when other projects try to consume the framework, it does not work. The only thing downloaded is top level framework pom.

I have tried adding some dependency entries to one or more of the various modules, but no matter which one I add, I get a circular dependency error. I also tried creating a 2nd top level pom file with no modules and a few dependencies to overwrite the one in the repository manager. This causes some of the dependencies to be downloaded, but then the maven build will hang in random places. based on windows task manager, it looks like its in an endless loop. So a 2nd pom file does not appear to be the answer (or im doing it wrong).

my framework pom file looks something like this:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>framework_snt</groupId>
  <artifactId>SFP</artifactId>
  <packaging>pom</packaging>
  <name>SFP framework</name>
  <version>6.3</version>

  <modules>
.... 50+ modules here
  </modules>

and then the usual properties, dependency management and pluginManagement entries for a top level pom.

in the consuming module I just have the following:

<dependency>
  <groupId>framework_snt</groupId>
  <artifactId>SFP</artifactId>
  <version>6.3</version>
  <type>pom</type>
</dependency>

This is in the top level pom so all submodules have access to the framework libraries to make it easier on the developers.

How do I set things up so so all the dependent jar files will be downloaded by my consuming projects ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

蝶…霜飞 2025-01-02 18:37:31

听起来您的框架项目生成了多个 jar 工件,每个子模块都有一个,但父项目没有 jar 工件。因此,声明对父项目的 pom 的依赖并不是您想要做的。相反,您需要声明对每个框架项目的子模块的依赖关系。

我有一个类似的设置,其中有一个包含多个模块的“工具包”项目(每个模块生成一个 jar 工件)。然后在我的其他项目中,我声明对我需要使用的任何模块的依赖关系。但是,我没有声明对我的“工具包”父项目 pom 文件的依赖关系。相反,我只是声明对子模块 jar 工件的依赖关系。

<dependency>
  <groupId>com.mycompany.toolkits</groupId>
  <artifactId>file-utils</artifactId>
  <version>1.0.0</version>
</dependency>

请注意,我的依赖项声明指向我的子模块之一,并且没有像您那样声明 pom 。如果你想真正明确,你可以声明 jar

It sounds like your framework project produces several jar artifacts, one for each child module, but no jar artifact for the parent project. Thus, declaring a dependency on the parent project's pom is not what you want to do. Instead you need to declare a dependency on each of your framework project's child modules.

I have a similar setup where I have a "toolkit" project with several modules (each producing a jar artifact). Then in my other projects I declare dependencies on whatever modules I need to use. I do not, however, declare a dependency on my "toolkit" parent projects pom file. Instead I just declare dependencies on the child modules jar artifacts.

<dependency>
  <groupId>com.mycompany.toolkits</groupId>
  <artifactId>file-utils</artifactId>
  <version>1.0.0</version>
</dependency>

Notice that my dependency declaration points to one of my child module's and does not declare <type>pom</type> like you did. If you wanted to be really explicit you could declare <type>jar</type> instead.

梦毁影碎の 2025-01-02 18:37:31

您所称的framework pom 是多模块项目的parent pom。

虽然模块可以相互依赖,但它不能依赖于这个父 pom。这就是可能导致循环依赖的原因。

您将需要重新查看您的模块并确定哪些模块依赖于哪些模块并适当地指定依赖关系。此外,这些依赖项通常是 jar 依赖项 - 包含源代码和资源的打包。

Maven By Examples 是众多可用资源之一,它提供了更多信息信息。

The framework pom as you call it is the parent pom of your multi-module project.

While the modules can depend on each other, it cannot depend on this parent pom. This is what is possibly causing the circular dependency.

You will need to relook at your modules and identify which modules depend on which and suitably specify the dependencies. Also, these dependencies are typically jar dependencies - a packaging which will contain sources and resources.

Maven By Example is one of the many resources available which gives further information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文