user810430
user810430

Reputation: 11499

Why pom.xml ask a version for dependency?

In pom.xml for hibernate:

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
    </dependency>

there is not version. But when I add to my application pom in Eclipse I receive error that version must be. Why this difference? Thanks.

Upvotes: 3

Views: 1621

Answers (4)

Calin Andrei
Calin Andrei

Reputation: 176

There are two ways of resolving these issue:

-insert yourself the version such that Maven knows what dependency you need (it either searches in the local repository for it or downloads from a maven repository or you can give it a link from where to download it)

-add a parent that uses the artifact that you are calling and then you don't need the version (it takes the parent version)

Upvotes: 1

Guillaume Polet
Guillaume Polet

Reputation: 47637

The extract you saw in the dependencies of hibernate actually has a version which is defined in a parent pom, in its dependencyMgmt section. This allows to only define in one place the version to use and all children of that parent pom only need to indicate which dependency they want and they automatically get the version specified in the parent.

Add a <version> in your case, or also use a dependencyMgmt section in your pom.xml to indicate the version of hibernate-jpa-2.0-api you want.

Upvotes: 1

Arnon Rotem-Gal-Oz
Arnon Rotem-Gal-Oz

Reputation: 25929

The 2.0 is the version of the JPA supported not the version of the artifact

try

<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.1.Final</version>
</dependency>

Arnon

Upvotes: 4

alex
alex

Reputation: 490597

Maven needs to know what version to download/check.

Add a version element as a child of dependency.

Upvotes: 2

Related Questions