英文:
How to update parent dependency after i update children denpendency using maven
问题
我使用IDEA,我的Spring Boot应用程序包含多个模块,如下所示:
parent
-web
-service
-dao
在service
模块的pom.xml
中有一个名为common:1.2.0-SNAPSHOT
的jar依赖项。我将其版本更新为1.3.0-SNAPSHOT
,然后执行了Maven重新导入并运行了mvn clean install -U
命令,但是这两个版本仍然存在于依赖列表中。在依赖树中,也存在两个jar依赖项。此外,当我运行应用程序时,它抛出了一个NoClassDefFoundError
错误,而我已经在1.3.0-SNAPSHOT
中添加了该类。
这是我的Maven依赖树:
service:jar
+- dao:jar
\- common:jar:1.3.0-SNAPSHOT
web:jar
+- service:jar
+- dao:jar
\- common:jar:1.2.0-SNAPSHOT
\- others:jar
service
模块的pom.xml中的依赖项配置如下:
<dependency>
<groupId>com</groupId>
<artifactId>common</artifactId>
<version>1.3.0-SNAPSHOT</version>
</dependency>
我该如何更新这个依赖项?
英文:
I use IDEA,My springboot app contains multiple modules like that:
parent
-web
-service
-dao
There is a jar dependency common:1.2.0-SNAPSHOT
in service
module defined in pom.xml, I updated its version to 1.3.0-SNAPSHOT
, after that i do maven reimport and run mvn clean install -U
but these two versions still in dependencies list, and in dependency tree, two jar in the dependencies, also when i run the app, it throw NoClassDefFoundError
error which i added in 1.3.0-SNAPSHOT
This is my maven dependenct tree:
service:jar
+- dao:jar
\- common:jar:1.3.0-SNAPSHOT
web:jar
+- service:jar
+- dao:jar
\- common:jar:1.2.0-SNAPSHOT
\- others:jar
service pom dependency:
<dependency>
<groupId>com</groupId>
<artifactId>common</artifactId>
<version>1.3.0-SNAPSHOT</version>
</dependency>
How can i update the dependency?
答案1
得分: 0
如@Haroon @chrylis所说,我检查了父级pom.xml
,并在此pom中找到配置了<parent>
。
<parent>
<groupId>insight.plat</groupId>
<artifactId>insight-bom-base</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
在pom insight-bom-base
中,配置了common 1.3.0-SNAPSHOT
,所以Web模块依赖于此版本而不是1.2.0-SNAPSHOT
版本。
<dependencyManagement>
<dependency>
<groupId>com</groupId>
<artifactId>common</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependencyManagement>
正如Maven文档中的传递性依赖所示,
依赖管理 - 这允许项目作者在遇到传递性依赖或在未指定版本的依赖项中直接指定要使用的工件版本。
在前面一节的示例中,即使A不直接使用D,也将D直接添加到了A中。
相反,A可以将D作为依赖项包含在其dependencyManagement部分中,并在引用D时直接控制使用哪个版本,如果需要的话。
父级dependencyManagement
的优先级高于传递性依赖,因此在服务模块中,它使用common 1.2.0-SNAPSHOT
。
英文:
As @Haroon @chrylis said, i checked the parent pom.xml
and found <parent>
configured in this pom.
<parent>
<groupId>insight.plat</groupId>
<artifactId>insight-bom-base</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
in pom insight-bom-base
, common 1.3.0-SNAPSHOT
is configured, so web module depend this version not version 1.2.0-SNAPSHOT
.
<dependencyManagement>
<dependency>
<groupId>com</groupId>
<artifactId>common</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependencyManagement>
As maven doc Transitive Dependencies shows,
Dependency management - this allows project authors to directly specify the
versions of artifacts to be used when they are encountered in transitive
dependencies or in dependencies where no version has been specified.
In the example in the preceding section a dependency was directly added to A even though
it is not directly used by A.
Instead, A can include D as a dependency in its dependencyManagement section and directly
control which version of D is used when, or if, it is ever referenced.
The parent dependencyManagement
has higher priority than Transitive Dependencies, so in service module, it use common 1.2.0-SNAPSHOT
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论