Java 没有版本的Maven依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29476472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
maven dependency without version
提问by yuranos
Recently I've been working on some improvements in a project developed some time ago, and here's what I found. A lot of dependencies in the pom files go without versions specified, and yet they are resolved. The project consists of 1 root module and 2 submodules. The Aggregator pattern is used, meaning there's no dependencyManagement section at all. The upper-project simply aggregates 2 modules and that's all it does. Subprojects don't refer to it as to a parent. They have a different parent. What I can't grasp is that neither subprojects themselves nor their parent(as a matter of fact, it doesn't have dependencyManagement either) specify versions for some of the dependencies. For instance:
最近我一直在对前段时间开发的一个项目进行一些改进,这就是我的发现。pom 文件中的许多依赖项都没有指定版本,但它们已得到解决。该项目由 1 个根模块和 2 个子模块组成。使用了聚合器模式,这意味着根本没有dependencyManagement 部分。上层项目只是聚合了 2 个模块,仅此而已。子项目不将其称为父项目。他们有不同的父母。我无法理解的是,子项目本身和它们的父项目(事实上,它也没有dependencyManagement)都没有为某些依赖项指定版本。例如:
<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>
Can someone help me figure this out? Is maven handling versioning with some default strategy? What is that default strategy?
有人可以帮我解决这个问题吗?maven 是否使用一些默认策略处理版本控制?那默认策略是什么?
采纳答案by yuranos
Ok, I think I'm gonna answer it myself. Of course I took a look at dependency:tree, but all the dependencies that I mentioned were first-level members of the tree. What I failed to notice right away, is that dependencyManagement
is not present in the parent, but it is however present in the submodules, and what is more interesting it contains:
好吧,我想我会自己回答。当然,我查看了dependency: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>
I've never used Spring IO Platform before, so this is a totally new concept for me. As it turns out the platform includes quite a few preconfigured dependencies: http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions
我以前从未使用过 Spring IO Platform,所以这对我来说是一个全新的概念。事实证明,该平台包含不少预配置的依赖项:http: //docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions
回答by Ozgen
It is impossible for maven to work without defining versions of the artifacts. They should be defined somewhere in dependencyManagement tag either in the submodule or parent. Please check your pom hierarchy. Use mvn help:effective-pom
in the submodule directory of the project. Also you can use mvn dependency:tree
in order to find out which artifacts - along with full artifact information including version numbers - are resolved in the result of dependency management.
Maven 不可能在不定义工件版本的情况下工作。它们应该在子模块或父模块中的dependencyManagement 标记中的某处定义。请检查您的 pom 层次结构。使用mvn help:effective-pom
该项目的子模块目录。您还可以使用mvn dependency:tree
以找出在依赖项管理的结果中解决了哪些工件 - 以及包括版本号在内的完整工件信息。
回答by radzimir
Use
用
mvn -P<my_profile_of_interest> help:effective-pom -Dverbose
Verbose mode (Since: 3.2.0) adds XML comments containing precise reference to a place where dependency declaration is coming from.
详细模式(自:3.2.0 起)添加了 XML 注释,其中包含对依赖声明来自的位置的精确引用。