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>
what will the version be
in a simple project, no subproject
as a dependency in another project and that project use foo-bar-1.0.0
of your question: If you don't specify a version there are various different outcomes: a) you will get an error... 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.
Maven won't allow any other either. Build will fail if version is not found.
version. It is the sub element of project. It specifies the version of the artifact under given group. File: pom.xml.
model version is the version of project descriptor your POM conforms to. It needs to be included and is set. The value 4.0. 0 just indicated that it is compatible Maven 3.
Part 1. of your question: If you don't specify a version there are various different outcomes:
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) 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) 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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With