Maven Child模块不继承父母'使用阴影插件时的POM属性

发布于 2025-01-23 01:52:10 字数 3252 浏览 2 评论 0原文

我有一个多模块项目,其结构如下:

-ParentModule
  -AggregateModule
    -pom.xml
    -ShadedModule
      -src
      -pom.xml
  -pom.xml

因此,本质上,我试图为 shadedModule 创建一个阴影jar ,它是 gentemegateModule的子模块/子模块,这是 parendmodule 的子模块/子。

当我去构建 shadedModule 时,它就不会出错。但是,我遇到的问题是,当我查看生成的POM时,没有解决 shadedModule 所依赖的POM属性。上述POM的顶部看起来像

  <parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>aggregate-module</artifactId>
    <version>${parent-module.version}</version>
  </parent>

  <groupId>com.foo.bar</groupId>
  <artifactId>shaded-module</artifactId>
  <version>${shaded-module.version}</version>

,但是如果我构建 shadedModule 而没有阴影插件,则属性可以很好地解决,并且生成的POM看起来应有。

该计划是使用 shadedModule 作为另一个项目的依赖性。但是,当试图构建此其他项目时,它会出现错误:

Could not find artifact com.foo.bar:aggregate-module:pom:${parent-module.version}

无论如何,我需要依靠 parendmodule 进行依赖关系管理等。关于如何解决这个问题的见解?

POM的简化版本看起来像:

shadedModule

<parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>aggregate-module</artifactId>
    <version>${parent-module.version}</version>
</parent>
<groupId>com.foo.bar</groupId>
<artifactId>shaded-module</artifactId>
<version>${shaded-module.version}</version>
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                      ...relocate packages and exclude some deps
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
.
.

cotregateModule

<parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>parent-module</artifactId>
    <version>${parent-module.version}</version>
</parent>
<packaging>pom</packaging>
<artifactId>aggregate-module</artifactId>
<modules>
   <shaded-module>
   .
   .
</modules>

parendmodule

<artifactId>parent-module</artifactId>
<version>${parent-module.version}</version>
<packaging>pom</packaging>
<properties>
  <parent-module.version>2.0</parent-module.version>
  <shaded-module.version>2.2</shaded-module.version>
</properties>
<modules>
  <module>aggregate-module</module>
  .
</modules>
<dependencyManagement>
  .
  .

I have a multi-module project with a structure that goes as:

-ParentModule
  -AggregateModule
    -pom.xml
    -ShadedModule
      -src
      -pom.xml
  -pom.xml

So in essence, I'm trying to create a shaded jar for ShadedModule which is a submodule/child of AggregateModule, which is a submodule/child of ParentModule.

When I go to build ShadedModule it completes without error. The issue I'm having however is when I look at the POM that is generated, none of the POM properties which ShadedModule relies on are resolved. The top of the aforementioned POM looks like

  <parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>aggregate-module</artifactId>
    <version>${parent-module.version}</version>
  </parent>

  <groupId>com.foo.bar</groupId>
  <artifactId>shaded-module</artifactId>
  <version>${shaded-module.version}</version>

But if I build ShadedModule without the shaded plugin, the properties are resolved fine and the generated POM looks as it should.

The plan is to use ShadedModule as a dependency for yet another project. But when trying to build this other project it fails with error:

Could not find artifact com.foo.bar:aggregate-module:pom:${parent-module.version}

Anyways I need to rely on ParentModule for dependency management and so on. Any insights on how to resolve this?

Simplified versions of the POMs look like:

ShadedModule

<parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>aggregate-module</artifactId>
    <version>${parent-module.version}</version>
</parent>
<groupId>com.foo.bar</groupId>
<artifactId>shaded-module</artifactId>
<version>${shaded-module.version}</version>
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                      ...relocate packages and exclude some deps
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
.
.

AggregateModule

<parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>parent-module</artifactId>
    <version>${parent-module.version}</version>
</parent>
<packaging>pom</packaging>
<artifactId>aggregate-module</artifactId>
<modules>
   <shaded-module>
   .
   .
</modules>

ParentModule

<artifactId>parent-module</artifactId>
<version>${parent-module.version}</version>
<packaging>pom</packaging>
<properties>
  <parent-module.version>2.0</parent-module.version>
  <shaded-module.version>2.2</shaded-module.version>
</properties>
<modules>
  <module>aggregate-module</module>
  .
</modules>
<dependencyManagement>
  .
  .

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文