【问题标题】:How maven handle version for children jarmaven如何处理儿童jar的版本
【发布时间】:2022-01-22 22:00:29
【问题描述】:

我有多模块 Maven 项目。在parem pom.xml 的内部,我在properites 标记中设置版本,比如说log4j-core 库。 在儿童内部(我们称之为 child.jar)我将 log4j 添加为依赖项。

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
</dependency>

没有版本,所以在运行dependency:tree 之后,log4j 具有从父pom.xml 文件中获取的正确版本。所以这里对我来说一切正常。

但是我想在我的 spring boot 项目中重用这个child.jar,但是我没有在 log4j 的父 pom 版本中写。所以在运行 dependency:tree 之后,我可以看到版本是错误的。 我可以看到 spring-boot-starter 包含 log4j-to-slf4j 但版本不同,并且由于某种原因,我的 log4j-core 与 spring boot 中包含的 jar 具有相同的版本。

所以我的问题是,我的 child.jar 不应该有我为 log4j 设置的第一个项目的版本吗?还是我需要在 child.jar 中具体说明 log4j 的版本?

【问题讨论】:

  • 只需在你的spring boot项目中定义log4j的依赖,它会覆盖spring boot给出的那个...

标签: java spring-boot maven


【解决方案1】:

如果省略版本,则它是从父代间接继承的。如果您在另一个项目中导入您的子模块,它将间接继承父级的 log4j-core 版本。

dependencyManagement标签或你项目的父/子模块的dependency标签中定义版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 2012-06-21
    相关资源
    最近更新 更多