为什么有时会跳过maven依赖关系中的版本号? [英] Why version number in maven dependency is skipped at times?

查看:296
本文介绍了为什么有时会跳过maven依赖关系中的版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对maven的功能相当新鲜。
我已经看到在pom.xml中放置了依赖关系,有时候只提及了groupID和artifact id,并且跳过了版本。为什么是这样?
例如,以下依赖关系来自springource网站 http://spring.io/guides / gs / authenticate-ldap /

 <依赖关系> 
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< / dependency>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-security< / artifactId>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-ldap< / artifactId>
< version> 3.2.4.RELEASE< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.directory.server< / groupId>
< artifactId> apacheds-server-jndi< / artifactId>
< version> 1.5.5< / version>
< / dependency>
< / dependencies>

但是stackoverflow中的其他地方也提到该版本不是可选的。

解决方案

是的,版本不是可选的。



考虑一个具有10个模块的模块应用程序,如module1,module2 .. module10.Assume所有这10个项目都使用 spring-boot-starter-web 。如果这10个模块是相互依赖的,那么您可能希望在这10个模块中使用相同版本的 spring-boot-starter-web



现在,您可以想象如果您要在所有这10个pom文件中保留相同的版本号,然后在要使用较新版本的弹簧引导起动的Web 。如果这个信息可以集中管理,那不是更好吗?



Maven已经知道了一个< dependencyManagement /> 标签来解决这个问题并集中依赖关系信息。



对于您提供的示例,下面的链接集将帮助您了解版本号是如何解决即使它不在您正在查看的pom中。



查看您正在查看的pom的父标记( https://github.com/spring-guides/gs-authenticating-ldap/ blob / master / complete / pom.xml



现在让我们去看看父项,看看是否在该pom的dependencyManagement部分指定了版本( https ://github.com/spring-项目/弹簧引导/斑点/主/弹簧引导起动器/弹簧引导起动父/ pom.xml中)。不,也没有定义。现在看看父母的父母。 https://github.com/spring -projects /弹簧引导/斑点/主/弹簧引导依赖性/ pom.xml的。哦,是的,我们有版本号。



类似于dependencyManagement,插件可以在pom的pluginManagement部分进行管理。



希望解释。



参考:依赖管理 pluginManagement


I am fairly new to maven's capabilities.. I have seen that in pom.xml where dependencies are put, at times, only groupID and artifact id are mentioned and version is skipped. why is this? For example the below dependency is from springsource website 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>

But elsewhere in stackoverflow it was also mentioned that version is not optional. I would be glad if someone could explain this.

解决方案

Yes, version is not optional.

Consider a multimodule application which has 10 modules, say module1, module2.. module10.Assume that all of these 10 projects use the spring-boot-starter-web. In case these 10 modules are interdependent, you might want to use the same version of the spring-boot-starter-web in each of these 10.

Now just imagine how complicated it would be if you were to maintain the same version number in all of these 10 pom files and then update all of them when you want to use a newer version of spring-boot-starter-web. Wouldn't it be better if this information can be managed centrally?

Maven has got something known a <dependencyManagement/> tag to get around this and centralize dependency information.

For the example which you have provided, below set of links will help you understand how the version number is resolved even though it's not present in the pom which you are looking at.

Look at the parent tag of the pom you are looking at (https://github.com/spring-guides/gs-authenticating-ldap/blob/master/complete/pom.xml)

Now lets go to that parent and see if the versions are specified in the dependencyManagement section of that pom(https://github.com/spring-projects/spring-boot/blob/master/spring-boot-starters/spring-boot-starter-parent/pom.xml). No it's not defined there as well. Now lets look at the parent of parent. https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml. Oh yea, we have got the version numbers there.

Similar to dependencyManagement, plugins can be managed in the pluginManagement section of the pom.

Hope that explains it.

Refer : dependencyManagement, pluginManagement

这篇关于为什么有时会跳过maven依赖关系中的版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆