Maven的dependency沒有設置version問題記
今天一個同事問了在工程裏沒有看到某個dependency設置version的話,是如何確定的版本呢?
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
查了一下SO,主要說的來自dependencyManagement和transparent dependency。
使用mvn dependency:tree -DskipTests > a.txt
輸入文件,也沒有發現哪裏定義了版本。
然後發現了一個命令mvn help:effective-pom
可以查看每個module具體生效的pom。
The
effective-pom
goal is used to make visible the POM that results from the application of interpolation, inheritance and active profiles. It provides a useful way of removing the guesswork about just what ends up in the POM that Maven uses to build your project. It will iterate over all projects in the current build session, printing the effective POM for each.
內容大概是下面的格式:
<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>
<groupId>xxx.xxx.xxx</groupId>
<artifactId>xxx-xxx</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>xxx-xx-xx</module>
</modules>
<properties>
<maven.compiler.encoding>utf-8</maven.compiler.encoding>
</properties>
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
<dependencies>
...
</dependencies>
<repositories>
...
</repositories>
<pluginRepositories>
....
</pluginRepositories>
<build>
...
</build>
<reporting>
...
</reporting>
<profiles>
...
</profiles>
</project>
可以再加上-Dverbose=true
, 輸出的更直觀。
<dependency>
<groupId>org.elasticsearch.client</groupId> <!-- xxxx:xxx-product-spring-boot-dependencies:1.4.7-SNAPSHOT, line 58 -->
<artifactId>transport</artifactId> <!-- xxxx:xxx-product-spring-boot-dependencies:1.4.7-SNAPSHOT, line 59 -->
<version>5.2.2</version> <!-- xxxx:xxx-product-spring-boot-dependencies:1.4.7-SNAPSHOT, line 60 -->
附錄
- [Maven Helper插件]([https://maven.apache.org/plugins/maven-help-plugin/usage.html#::text=The%20help%3Aeffective%2Dpom%20Goal,uses%20to%20build%20your%20project.](https://maven.apache.org/plugins/maven-help-plugin/usage.html#::text=The help%3Aeffective-pom Goal,uses to build your project.))
- SO問題的鏈接