32

A multi-module parent POM declares the following BOM import:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.spring.platform</groupId>
      <artifactId>platform-bom</artifactId>
      <version>${spring.io.platform.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>

Then a module POM declares a Hibernate dependency:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
</dependency>

How do I find out with Maven command line or IntelliJ where the effective Hibernate version is defined?

Running mvn dependency:tree against my module yields:

...
[INFO] +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
...

which is not exactly helpful because it looks no different than if I managed the Hibernate version myself. If you have to do this manually you

  • start at platform-bom-2.0.3.RELEASE.pom, search for Hibernate -> nothing
  • go to its parent spring-boot-starter-parent-1.3.3.RELEASE.pom, search for Hibernate -> nothing
  • go to its parent spring-boot-dependencies-1.3.3.RELEASE.pom, search for Hibernate -> finally...

But what an ordeal. Of course you could check http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions but isn't that information Maven should be able to find on its own?

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198

6 Answers6

42

mvn help:effective-pom -Dverbose=true gives the information of location of pom from where an entry comes in effective pom in comment. reference: http://maven.apache.org/plugins/maven-help-plugin/effective-pom-mojo.html

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
user2772346
  • 791
  • 7
  • 7
29

I was trying to use mvn help:effective-pom -Dverbose from this other answer, but it didn't work for me because it was using maven-help-plugin:2.2, and -Dverbose was introduced in 3.2.0.

Instead, you should thus force the version in the command line:

mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:effective-pom -Dverbose=true -Doutput=effective-pom.xml

(better to use -Doutput because the file can be big and it is not convenient to read it in a terminal)

Didier L
  • 18,905
  • 10
  • 61
  • 103
  • 8
    If the dependency comes from a bom it nicely reports that. But if the bom also comes from another bom then this is not shown. – thehpi Mar 19 '21 at 12:50
  • 2
    @thehpi and this is just insane, how easy this is with gradle (imo) and how _impossible_ it is with maven. – Eugene Sep 08 '22 at 12:21
  • I hit the same issue @thehpi describes. I did not find any other way but to manually inspect the content of all BOMs. – napets Jul 13 '23 at 15:37
5

In Eclipse, when viewing the pom in XML format (i.e in the "pom.xml" tab, not the "Overview" tab), simply put the mouse cursor over the artifact name and a popup will appear with the effective version and the location where it is defined.

enter image description here

Pino
  • 7,468
  • 6
  • 50
  • 69
2

According to How do I show the Maven POM hierarchy? it looks like it not possible with a simple command.

You should write your own plugin or script to climb the hierarchy to the top and find the artifact you are interested in.

Small Tip: to retrieve the version of an artifact you're using, you can open the pom.xml in the Idea Editor and hold Ctrl while hovering on the artifactId, and the full name of its pom will be displayed, with its version.

Community
  • 1
  • 1
Linuslabo
  • 1,568
  • 2
  • 24
  • 34
0

There are two things. First the output of dependency:tree prints out what the final result is. The question here is why you don't believe it? And why do you manage the version yourself if you are using a BOM...

Apart from that you could use:

mvn help:effective-pom

And if you search a little bit better than you will come to the following pom file which contains the version definition like this:

<hazelcast.version>3.5.5</hazelcast.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
<hikaricp.version>2.4.3</hikaricp.version>
<hikaricp-java6.version>2.3.13</hikaricp-java6.version>
<hornetq.version>2.4.7.Final</hornetq.version> 

which are exactly the version which is printed out already by dependency:tree.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 8
    Thanks, but all of that is in my Q already. I never said I didn't believe what `dependency:tree` printed and I never said I managed the version myself. The Q is "where the effective Hibernate version is defined". Also, I did list the POM you also mentioned. The point is, what you state as "search a little bit better" is IMO an ordeal. I was expecting Maven to be able to tell me right away where the version is defined (i.e. in which POM). – Marcel Stör Apr 19 '16 at 18:26
  • Sounds like a good idea for maven-dependency-plugin or any other plugin which can solve such problem... – khmarbaise Apr 19 '16 at 18:36
  • 1
    mvn help:effective-pom -Dverbose=true gives the information of location of pom from where an entry comes in effective pom. – user2772346 Sep 27 '19 at 23:37
-1

My answer would be really similar to @Didier L. I was getting error due to the .xml file extension mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:effective-pom -Dverbose=true -Doutput=effective-pom