Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to trace origin of a property in maven pom?

I have a complex maven project with a lot of managed dependencies, and have a little problem tracing versions of these dependencies. For example, spring libraries' version is guided by a property value {spring.version} - but I have no idea which project this property is coming from.

Using mvn dependency:tree I can see the final result where all versions are resolved, but it does not go deep into detail to tell me where the winning dependency version is coming from, and why that version is a winner.

P.S. Version number is not coming from my parent pom.

like image 940
Alexander Avatar asked Mar 30 '17 17:03

Alexander


People also ask

How do I get property from POM XML?

In maven pom. xml , a property is accessed by using ${property_name} . You can define your custom properties in Maven.

How do you find the value of POM files?

The plugin is part of the Maven Super Pom and executed during the process-resources phase of the Jar Default Lifecyle. The only thing you have to do is to active filtering. How you make this property then available to your Java application is up to you - reading it from the classpath would work.

What information does POM contain?

What is a POM? A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.


1 Answers

You could give help:effective-pom a go. Just make sure that you use the 3.2.0 version (or later) together with the -Dverbose=true flag set. This will print out the source of the POM value.

To force the right version of the plugin:

<build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-help-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
</build>

To use it:

%> mvn help:effective-pom -Dverbose=true 

This will print out the following:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 2019-07-24T15:28:33+02:00            -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective POM for project                                              -->
<!-- 'org.example:test-project:jar:0.0.1-SNAPSHOT'                          -->
<!--                                                                        -->
<!-- ====================================================================== -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 5 -->
  <parent>
    <groupId>org.springframework.boot</groupId>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 16 -->
    <artifactId>spring-boot-starter-parent</artifactId>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 17 -->
    <version>2.0.5.RELEASE</version>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 18 -->
    <relativePath />  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 19 -->
  </parent>
  <groupId>org.example</groupId>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 7 -->
  <artifactId>test-project</artifactId>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 8 -->
  <version>0.0.1-SNAPSHOT</version>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 9 -->
  <name>Test Project</name>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 12 -->
  <description>Blabla.</description>  <!-- org.example:test-project:0.0.1-SNAPSHOT, line 13 -->
  <url>https://projects.spring.io/spring-boot/#/spring-boot-starter-parent/test-project</url>  <!-- org.springframework.boot:spring-boot-starter-parent:2.0.5.RELEASE, line 14 -->
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 12 -->
      <url>http://www.apache.org/licenses/LICENSE-2.0</url>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 13 -->
    </license>
  </licenses>
  <developers>
    <developer>
      <name>Pivotal</name>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 18 -->
      <email>[email protected]</email>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 19 -->
      <organization>Pivotal Software, Inc.</organization>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 20 -->
      <organizationUrl>http://www.spring.io</organizationUrl>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 21 -->
    </developer>
  </developers>
  <properties>
    <activemq.version>5.15.6</activemq.version>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 28 -->
    <antlr2.version>2.7.7</antlr2.version>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 29 -->
    <appengine-sdk.version>1.9.64</appengine-sdk.version>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 30 -->
    <artemis.version>2.4.0</artemis.version>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 31 -->
    <aspectj.version>1.8.13</aspectj.version>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 32 -->
    ...
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 208 -->
        <artifactId>spring-boot</artifactId>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 209 -->
        <version>2.0.5.RELEASE</version>  <!-- org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE, line 210 -->
      </dependency>
      ...
    </dependencies>
  </dependencyManagement>
</project>
like image 172
Daniel Avatar answered Oct 13 '22 01:10

Daniel