Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What will happen if I don't specify a version for a Maven dependency?

Tags:

maven

i have seen in the project maven dependency specified like the following,

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
        </dependency>

there is no version defined in the dependency, so what will happen if i don't give version name and why it is given like above.

would some one explain the reason please.

like image 802
Java Questions Avatar asked May 03 '13 07:05

Java Questions


People also ask

What happens if Maven dependency version is not specified?

Each maven dependency defined in the pom must have a version either directly or indirectly for example, through dependencyManagement or parent. That being said, if the version is not given, then the version provided in the dependencyManagement or the parent pom will be used.

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

Does Maven override dependency version?

By taking advantage of Maven's nearest definition logic, developers can override the version of a dependency by declaring it on the root pom. xml file.

Is it possible for Maven to pull automatically the latest version?

Maven Dependency Updating Using the CLIThe Versions Maven Plugin is a Maven Plugin that can be used to automatically scan pom. xml dependencies and look up new versions.


1 Answers

I don't think you can do that in the ordinary dependency section of your poject. The only case I know that this is allowed is when you inherit a parent project with a <dependencyManagement> section, which is used to coordinate dependency versions across a set of projects. Then you can use the "shorthand" definition, without the version. But it would still have a version, which it inherits from the dependency defined in the parent project.

There are some other places in the pom you can drop the version as well, but those are not directly relevant to including dependencies (like plugins/exludes etc).

like image 133
NilsH Avatar answered Sep 30 '22 04:09

NilsH