我对 Maven 的功能还很陌生..
我发现在 pom.xml 中放置依赖项的地方,有时只提到 groupID 和artifact id,而跳过 version。为什么是这样?
例如以下依赖项来自 springsource 网站http://spring.io/guides/gs/authenticating-ldap/
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-jndi</artifactId>
<version>1.5.5</version>
</dependency>
</dependencies>
但在 stackoverflow 的其他地方也提到版本不是可选的。如果有人能解释这一点,我会很高兴。
是的,版本不是可选的。
考虑一个多模块应用程序,它有 10 个模块,例如 module1、module2.. module10。假设所有这 10 个项目都使用spring-boot-starter-web
。如果这 10 个模块相互依赖,您可能需要使用相同版本的spring-boot-starter-web
在这 10 个中的每一个中。
现在想象一下,如果您要在所有这 10 个 pom 文件中维护相同的版本号,然后当您想要使用较新版本的时更新所有这些文件,那将是多么复杂spring-boot-starter-web
。如果这些信息能够集中管理不是更好吗?
Maven 有一些已知的东西<dependencyManagement/>
标签来解决这个问题并集中依赖信息。
对于您提供的示例,下面的链接集将帮助您了解如何解析版本号,即使它不存在于您正在查看的 pom 中。
查看您正在查看的 pom 的父标签(https://github.com/spring-guides/gs-authenticating-ldap/blob/master/complete/pom.xml)
现在让我们转到该父级并查看该 pom 的 dependencyManagement 部分中是否指定了版本(https://github.com/spring-projects/spring-boot/blob/master/spring-boot-starters/spring-boot-starter-parent/pom.xml)。不,它也没有在那里定义。现在让我们看看父母的父母。https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependency/pom.xml。哦,是的,我们在那里得到了版本号。
与dependencyManagement类似,插件可以在pom.xml的pluginManagement部分进行管理。
希望能解释一下。
Refer : 依赖管理, 插件管理
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)