gpt4 book ai didi

java - 可以将父版本作为属性送给 child 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:16:21 24 4
gpt4 key购买 nike

这是关于 Maven POM 的

如果我想让我的父版本也成为我的依赖项的版本,我必须设置一个值为 ${project.parent.version} 的属性。

当我的主 POM 的子项(其中有 ${project.parent.version} 属性,因为它是我不管理的某个项目的父级)重新计算属性并认为值创建的属性现在是我的主 POM 的版本。

--SuperParent (not in my Administration) | Version = 1.2.3

----MainPom | Version = 1.0.0 | Property <test>${project.parent.version}</test> -> 1.2.3

------Child Pom | Version 1.0.0 | Property ${test} is now 1.0.0

<project>
<!-- Super Pom -->
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.2.3</version>
</project>

<project>
<!-- MainPom -->
<groupId>othergroupId</groupId>
<artifactId>otherartifactId</artifactId>
<version>1.0.0</version>
<parent>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.2.3</version>
</parent>
<properties>
<dependency.version>${project.parent.version}</dependency.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dependencyGroupId<groupId>
<artifactId>dependency</artifactId>
<version>${dependency.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
<project>
<!-- ChildPom -->
<groupId>childGroupId</groupId>
<artifactId>childArtifactId</artifactId>
<version>1.0.0</version>
<parent>
<groupId>othergroupId</groupId>
<artifactId>otherartifactId</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>dependencyGroupId<groupId>
<artifactId>dependency</artifactId>
</dependency>
</dependencies>
</project>

最后是 Child Pom 1.0.0 而不是 1.2.3 中的属性 ${dependency.version}。这是 Maven 想要的行为吗?我该怎么做才能让它发挥作用?

不能改变的事情:

  • super Pom
  • 主 Pom 版本

最佳答案

Maven首先处理继承构建有效的pom然后处理变量扩展。

换句话说,父子 pom 内容被处理为每个子 pom 的单个合并文件。因此,当处理您的子 pom 时,${project.parent.version} 是 1.0.0,而不是 1.2.3。

我找不到引用 pom 的“祖 parent ”的方法,所以似乎唯一的解决方案是将版本作为静态数字放在 parent.version 和 properties.dependency.version 中。

关于java - 可以将父版本作为属性送给 child 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40359934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com