Maven依赖树输出中的“+-”和“\-”有什么区别?

What is the difference between "+-" and "\-" in maven dependency tree output?

如果我们考虑以下示例,“+-”和“\-”符号之间有什么区别,它们表示什么?

[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] +- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
[INFO] |  \- commons-validator:commons-validator:jar:1.2.0:compile
[INFO] |     \- commons-digester:commons-digester:jar:1.6:compile
[INFO] |        \- (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.0)
[INFO] \- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO]    \- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO]       \- commons-collections:commons-collections:jar:2.0:compile

这些符号没有任何意义,它们只是为了更好地读取树的输出!

这是一个更复杂的输出,可以更好地了解它在 spring-webmvc 依赖项上的作用:

[INFO] +- org.springframework:spring-webmvc:jar:4.2.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.2.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.2.2.RELEASE:compile
[INFO] |  |     \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.2.2.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.2.2.RELEASE:compile

将依赖树视为层次:第一层对应直接依赖;第二层对应那些直接依赖的传递依赖等

基本上,如果同一个神器在同一个层次上有多个依赖,就会显示一个+-,否则会显示一个\-,表示一个"end" 树(即通往叶子的路径)。

加号表示同一级别的多个节点,而 - 符号表示该级别的一个节点。

因此,在您的情况下,maven-dependency-plugin+ 符号)在第一级具有传递依赖性 maven-reporting-impldoxia-site-renderer,然后只有 maven-reporting-impl具有 (- 符号) commons-validator 作为直接传递依赖等。

\- 符号表示该节点是为当前父节点列出的最后一个兄弟节点

对于同一级别的多个依赖项,\- 将显示该级别的最后一个依赖项,+- 将显示该级别的所有其他依赖项。

也许“+-”表示树层次结构中的非最后节点

“\-”表示树层次结构中的最后一个节点

我猜测他可能使用了某种尾部为索引的数据结构

例如

root:
....+-(first chirld)
....+-(second chirld)
........\-(last chirld)
....\-(last chirld)

这里有一个关于 [maven-dependency-tree][https://github.com/apache/maven-dependency-tree] 依赖的更复杂的输出:

[INFO] Scanning for projects...
[INFO]
[INFO] -----------< org.apache.maven.shared:maven-dependency-tree >------------
[INFO] Building Apache Maven Dependency Tree 3.1.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ maven-dependency-tree ---
[INFO] org.apache.maven.shared:maven-dependency-tree:jar:3.1.1-SNAPSHOT
[INFO] +- org.apache.maven:maven-core:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-model:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-settings:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-settings-builder:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-repository-metadata:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-artifact:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-plugin-api:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-model-builder:jar:3.0.5:compile
[INFO] |  +- org.apache.maven:maven-aether-provider:jar:3.0.5:compile
[INFO] |  |  \- org.sonatype.aether:aether-spi:jar:1.13.1:compile
[INFO] |  +- org.sonatype.aether:aether-impl:jar:1.13.1:compile
[INFO] |  +- org.sonatype.aether:aether-util:jar:1.13.1:compile
[INFO] |  +- org.sonatype.sisu:sisu-inject-plexus:jar:2.3.0:compile
[INFO] |  |  \- org.sonatype.sisu:sisu-inject-bean:jar:2.3.0:compile
[INFO] |  |     \- org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile
[INFO] |  |        \- org.sonatype.sisu:sisu-guava:jar:0.9.9:compile
[INFO] |  +- org.codehaus.plexus:plexus-interpolation:jar:1.14:compile
[INFO] |  +- org.codehaus.plexus:plexus-utils:jar:2.0.6:compile
[INFO] |  +- org.codehaus.plexus:plexus-classworlds:jar:2.4:compile
[INFO] |  \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] |     \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] +- org.codehaus.plexus:plexus-component-annotations:jar:2.0.0:compile (optional)
[INFO] +- org.sonatype.aether:aether-api:jar:1.13.1:compile (optional)
[INFO] +- org.eclipse.aether:aether-api:jar:1.1.0:compile (optional)
[INFO] \- org.eclipse.aether:aether-util:jar:1.1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.519 s
[INFO] Finished at: 2021-12-27T16:06:44+08:00
[INFO] ------------------------------------------------------------------------