1

I am including another pom file as parent in my current maven project.

There is a dependency for hibernate 3.3.2 defined in parent pom file.

I want to use the latest version of hibernate 4.3.5 in my current project. my question is how to exclude the older version so that antlr and other dependencies gets properly generated in my war file.

I also want my war file not to have duplicate jar files

Please help

Knight
  • 43
  • 9
  • Is the dependency in the master defined directly as a dependency or is it defined in a dependenymanagement block? – Martin Nielsen Mar 30 '15 at 06:13
  • it is included as parent tag – Knight Mar 30 '15 at 07:23
  • We cannot help if you don't use the proper terminology. There is no such thing as a "master dependency". A "master pom" doesn't exist either. Your pom can reference a "parent", from which it will inherit some properties, or define "dependencies" for you project. Please post you pom file, so we can sort it out. – Samuel EUSTACHI Mar 30 '15 at 07:52
  • my pom.xml parent_pom parent_package 0.0.1 org.hibernate hibernate-core 4.3.5.Final – Knight Mar 30 '15 at 08:34
  • parent_pom.0.0.1.xml ---------------------- org.hibernate hibernate-core 3.3.2.GA – Knight Mar 30 '15 at 08:35
  • Ok so this is a dependency coming from the parent. In this case the solution is to do what Adrian Shum proposed. – Samuel EUSTACHI Mar 30 '15 at 11:57

1 Answers1

1

Just put the version you want in your own POM file.

When there are multiple versions of same artifact resolved transitively (through parent, or through transitive dependencies), Maven is going to resolve find the version to use. Normally it use the "nearest" one. If you are declaring the dependency in the POM of the project itself, it will always be the "nearest" and hence will be used.

In your case, just put hibernate:4.3.5 in your POM, and hence this version will be taken instead of hibernate:3.3.2 (which is declared in parent), no related transitive dependencies of hibernate:3.3.2 will be included in project.

Just one thing to be careful: such kind of version resolution is done only for same artifact, which means, artifact with same Group ID and Artifact ID. If the old version in parent is org.hibernate:hibernate:3.3.2 while the newer version is org.hibernate:hibernate-core:4.3.5, it will not work. In such case, you need some trick to explicitly exclude the dependency from parent, for which you can look into https://stackoverflow.com/a/7898553/395202 for one method.

Community
  • 1
  • 1
Adrian Shum
  • 38,812
  • 10
  • 83
  • 131