如何在maven模块中设置循环引用?

发布于 2025-01-03 02:34:10 字数 1918 浏览 4 评论 0原文

我在构建 Maven 项目时遇到这个问题...

mvn 项目父项设置如下:

<groupId>com.company.system.ping</groupId>
<artifactId>system-ping</artifactId>
<name>system-ping</name>    
<parent>
    <artifactId>parent_lvl_1</artifactId>
    <groupId>com.company.system</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

然后我查找所述父项的 POM 并找到这个:

<groupId>com.company.system</groupId>
<artifactId>parent_lvl_1</artifactId>
<packaging>pom</packaging>
<name>_proj_test</name>
<version>1.0-SNAPSHOT</version>
<parent>
    <artifactId>parent_lvl_0</artifactId>
    <groupId>com.company</groupId>
    <version>1</version>
</parent>

我最后查看第一个父项并看到这个:

<groupId>com.company</groupId>
<artifactId>parent_lvl_0</artifactId>
<packaging>pom</packaging>
<name>_main</name>
<version>1</version>
<description>The whole Projects</description>

现在我检查模块

<modules>
    <module>../_proj_test</module>

    ...

</modules>

:第一个父模块正在引用一个子模块!所以当我尝试时

mvn安装

on '_main' 我明白了:

[ERROR]   The project com.company.system:_proj_test:1.0-SNAPSHOT (C:\...\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: The repository system is offline but the artifact com.company:_main:pom:1 is not available in the local repository. and 'parent.relativePath' points at wrong local POM @ line 4, column 10 -> [Help 2]
[ERROR]

我将其翻译为:您的父母需要一个需要您回来的模块。如果我注释掉模块中的所有内容,我可以正确安装所有内容,但这对我来说不行!如何在不构建模块依赖项的情况下构建父级?

谢谢你!

I have this problem with building a maven project...

A mvn project parent is set like this:

<groupId>com.company.system.ping</groupId>
<artifactId>system-ping</artifactId>
<name>system-ping</name>    
<parent>
    <artifactId>parent_lvl_1</artifactId>
    <groupId>com.company.system</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

Then I look for said parent's POM and find this:

<groupId>com.company.system</groupId>
<artifactId>parent_lvl_1</artifactId>
<packaging>pom</packaging>
<name>_proj_test</name>
<version>1.0-SNAPSHOT</version>
<parent>
    <artifactId>parent_lvl_0</artifactId>
    <groupId>com.company</groupId>
    <version>1</version>
</parent>

I finally look at the first parent and see this:

<groupId>com.company</groupId>
<artifactId>parent_lvl_0</artifactId>
<packaging>pom</packaging>
<name>_main</name>
<version>1</version>
<description>The whole Projects</description>

Now I check the modules:

<modules>
    <module>../_proj_test</module>

    ...

</modules>

The first parent module is referencing a child! So when I try

mvn install

on '_main' I get this:

[ERROR]   The project com.company.system:_proj_test:1.0-SNAPSHOT (C:\...\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: The repository system is offline but the artifact com.company:_main:pom:1 is not available in the local repository. and 'parent.relativePath' points at wrong local POM @ line 4, column 10 -> [Help 2]
[ERROR]

I translate this to: you parent requieres a module which requires you back. If I comment out everything in modules I can install everything correctly but this is NOT OK for me! How can I build the parent without building the module dependencies?

Thank you!

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

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

发布评论

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

评论(1

朕就是辣么酷 2025-01-10 02:34:10

该配置对我来说看起来很奇怪,主要是因为您的“_proj_test”(“_main”的子级)位于同一级别。

如何在不构建模块依赖项的情况下构建父级?

尝试mvn -N install

至于项目结构,我会这样做:

1) $basedir 和 '_main' pom.xml 应该包含这个

<modules>
  <module>_proj_test</module>
</modules>

2) $basedir/_proj_test 和 '_proj_test' pom.xml 应该包含这个

<modules>
  <module>system-ping</module>
</modules>

3) $basedir/_proj_test/system-ping 与 'system-ping' pom.xml (具有正确的父组 groupId - com.company.system 而不是 com.company

The config looks very weird to me, mainly because your '_proj_test' which is a child for '_main' is located on the same level.

How can I build the parent without building the module dependencies?

Try mvn -N install.

As for the project structure, I'd do it in such a way:

1) $basedir with '_main' pom.xml which should contain this

<modules>
  <module>_proj_test</module>
</modules>

2) $basedir/_proj_test with '_proj_test' pom.xml which should contain this

<modules>
  <module>system-ping</module>
</modules>

3) $basedir/_proj_test/system-ping with 'system-ping' pom.xml (with correct groupId of parent - com.company.system instead of com.company)

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