当我没有在Maven的pom.xml中指定它时,版本会是什么? [英] What will the version be when I don't specify it in the Maven's pom.xml?

查看:4591
本文介绍了当我没有在Maven的pom.xml中指定它时,版本会是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我用maven编写了一个项目,但我对maven pom.xml中的版本有疑问。

Recently I wrote a project with maven, but I have a question about the version in maven pom.xml.

如果我写了这样的依赖项

If I write such a dependency

<dependency>
    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
     <!--No version here-->
</dependency>

版本是什么


  1. 在一个简单的项目中,没有子项目

  1. in a simple project, no subproject

作为另一个项目的依赖项,该项目使用foo-bar-1.0。 0

as a dependency in another project and that project use foo-bar-1.0.0


推荐答案

问题的第1部分:如果不这样做指定一个版本有各种不同的结果:

Part 1. of your question: If you don't specify a version there are various different outcomes:

a)你会收到一个错误......

a) you will get an error...


[ERROR]   The project org.example:myproject:0.5-SNAPSHOT (D:\src\myproject\pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for foo:bar:jar is missing. @ line 39, column 14


b)如果你已经定义了在项目的父pom的依赖关系管理中的版本,然后该版本被采用。项目的父项不一定是封闭的超级项目。它可以只是一组合适的定义。

b) if you have defined the version in the dependency management of the project's parent's pom, then that version is taken. The parent of the project doesn't have to be an enclosing superproject. It can simply be a collection of appropriate definitions.

c)如果你的项目的另一个依赖项还依赖于foo:bar,并指定一个版本,则该版本被采用。 Maven 2有一种名为传递依赖关系的机制。如果没有为工件显式指定依赖项的版本,它将搜索依赖关系树并使用树中的最近定义。如果有两个最接近的定义,则第一个声明获胜(因为maven 2.0.9)。

c) if another dependency of your project also depends on foo:bar, and specifies a version, then that version is taken. Maven 2 has a mechanism called transitive dependencies. If the version of a dependency is not explicitly specified for an artifact, it searches the dependency tree and uses the nearest definition in the tree. If there are two nearest definitions, then the first declaration wins (since maven 2.0.9).

第2部分:我不确定,但也许是传递依赖机制也是这样的。但是文档(据我所知)并没有提到这种情况。

Part 2.: I am not sure, but maybe the transitive dependency mechanism also works that way. But the documentation (as far as I understood it) doesn't mention that case.

但不知怎的,我觉得你问题的第二部分没有意义:我想,为了将工件用作依赖项,您必须首先构建它。因此,在将依赖项本身用作依赖项之前,您必须知道它们的版本。

But somehow I feel that the second part of your question doesn't make sense: I guess that in order to use an artifact as a dependency, you would have to build it first. So you'd have to know the version of the dependencies well before it is used as a dependency itself.

这篇关于当我没有在Maven的pom.xml中指定它时,版本会是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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