yur*_*s87 44 java maven-3 spring-io
最近我一直在研究一段时间前开发的项目的一些改进,这就是我发现的.pom文件中的许多依赖项没有指定版本,但它们已被解析.该项目由1个根模块和2个子模块组成.使用聚合器模式,这意味着根本没有dependencyManagement部分.上层项目简单地聚合了2个模块,这就是它所做的一切.子项目不会将其称为父项.他们有不同的父母.我无法理解的是既没有子项目本身也没有它们的父项(事实上,它也没有依赖管理)为某些依赖项指定了版本.例如:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>imap</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?maven是否使用某种默认策略处理版本控制?什么是默认策略?
yur*_*s87 29
好的,我想我会自己回答.当然,我看了一下依赖:tree,但我提到的所有依赖项都是树的第一级成员.我没有立即注意到的是,dependencyManagement它在父级中不存在,但它存在于子模块中,它包含的内容更有趣:
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>1.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我之前从未使用过Spring IO平台,所以这对我来说是一个全新的概念.事实证明,该平台包含了相当多的预配置依赖项:http: //docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions
Ozg*_*gen 18
如果没有定义工件的版本,maven就不可能工作.它们应该在子模块或父模块中的dependencyManagement标签中的某处定义.请检查你的pom层次结构.使用mvn help:effective-pom该项目的子模块目录.您还可以使用mvn dependency:tree以便找出哪些工件 - 以及包括版本号在内的完整工件信息 - 在依赖关系管理的结果中得到解决.
rad*_*mir 11
使用
mvn -P<my_profile_of_interest> help:effective-pom -Dverbose
Run Code Online (Sandbox Code Playgroud)
详细模式(自:3.2.0 起)添加了 XML 注释,其中包含对依赖项声明来源位置的精确引用。
小智 11
pom 中定义的每个 Maven 依赖项都必须有一个直接或间接的版本,例如通过 dependencyManagement 或parent。也就是说,如果未给出版本,则将使用 dependencyManagement 或父 pom 中提供的版本。
例如:在下面给出的pom中(仅提到重要部分),没有为工件jstl提供版本。但是,在“mvn dependency:tree”中,显示包含jstl版本1.2。查看 spring-boot-starter-parent,对于版本 2.3.3.RELEASE pom,它包含 jstl 版本 1.2。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
....
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
....
</dependencies>
Run Code Online (Sandbox Code Playgroud)