如何列出 Maven 中的所有“dependencyManagment”?

How to list all `dependencyManagment` in Maven?

我在我的Maven项目中使用了一些BOM依赖,例如:

<dependencyManagement>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    ...
</dependencyManagement>

每当我需要添加依赖项时,我想知道该依赖项是否已在我导入的任何 dependencyManagement 中声明,这样我就不需要为其指定版本。

现在我手动做,去那些BOM文件的来源检查,但有时一个BOM也会导入其他BOM,例如:spring-boot-dependencies导入netty-bomjackson-bom。所以我想知道有没有办法列出(展平)我所有的 dependencyManagement?

我认为您可以使用 maven 做的最好的事情是 mvn help:effective-pom 和 grep 用于相关的依赖项。它将向您展示 the effective pom,包括扩展的 BOM dependencyManagement。

此外,如果您使用像 IntelliJ 这样的 IDE,它将显示一个 "arrow up" 符号表示托管依赖项,包括通过 BOM 引入的依赖项。