如何使用“依赖关系结构矩阵”和其他工具来分析IDEA中的依赖关系。
![](https://habrastorage.org/webt/86/he/s2/86hes28crptwprwlpcynpugcklm.png)
此翻译是IntelliJ IDEA系列的继续:
依赖矩阵
此功能仅在IntelliJ IDEA Ultimate中可用,而在Community版本中不可用。
IDEA , . , .
, , .
(Dependency Structure Matrix DSM) . -, build . , , «Analyze → Analyze Dependency Matrix...». IDEA Ultimate DSM Analysis.
:
![](https://habrastorage.org/webt/xy/og/us/xyogusjjgql37zijyzf-mwhzmma.png)
, .
![](https://habrastorage.org/webt/hh/h2/dz/hhh2dza-revyxq3x_d50ertvcgc.png)
IDEA , , , .
. — . . , . , . 99 , ... .
, , . , . .
, . , . . , , .
, , .
![](https://habrastorage.org/webt/-e/y4/b7/-ey4b7cqhxkwlzwwkq2dcbrmuzi.png)
, . ( ), IDEA .
![](https://habrastorage.org/webt/o-/_e/i7/o-_ei7pz27gls5k9kl_upu3if3u.png)
, , . , , .
, . , . , .
![](https://habrastorage.org/webt/n4/os/uw/n4osuwdyhhp3bf6hpccymxpjzm8.png)
. , , , . , .
DSM , , . , .
![](https://habrastorage.org/webt/wh/ml/tz/whmltzzvzmq67vmltycslc0ftri.png)
. , , . DSM :
![](https://habrastorage.org/webt/pb/ae/t1/pbaet1giw4bs_nowi14wxdakzrc.png)
, Owner 15 Pet, Pet 5 Owner.
DSM IDEA — , , .
DSM. , Find usages for dependencies. IDEA / , / .
, . service, - vet. :
![](https://habrastorage.org/webt/e8/jy/02/e8jy02kvk12ldid64sfwfcgr5e0.png)
, .
Maven
IntelliJ IDEA Ultimate, Community .
. , , . . , , ( ). , . Maven , . :
mvn dependency:tree -Dverbose -DoutputFile=dependencies.txt
Maven , ( ):
com.vojtechruzicka:spring-boot-actuator-example:jar:1.0.0-SNAPSHOT
+- org.springframework.boot:spring-boot-starter-actuator:jar:2.0.3.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter:jar:2.0.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot:jar:2.0.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.3.RELEASE:compile
| | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
| | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
| | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
| | | | \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
| | | \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
| | +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
| | \- org.yaml:snakeyaml:jar:1.19:runtime
, , , graphml tgf.
, , .
: verbose maven 3.x, Maven 2 .
, IDEA Maven. IntelliJ, 2019.1 , .
, pom.xml Shift + Ctrl + Alt + U ( ⌥ + ⇧ + ⌘ + U Mac). → Diagrams → Show Dependencies.
, , . . , Find , Ctrl + F.
![](https://habrastorage.org/webt/u7/su/mp/u7sumpyjvial2odxjmg_c1uu3ao.gif)
, . , , .
— . , .
![](https://habrastorage.org/webt/z1/tq/ig/z1tqigg4jagx_3havl6m-q0avc0.gif)
, , , Shift.
, .
![](https://habrastorage.org/webt/hz/rh/d_/hzrhd_sdfu5an2k96p3bzdrdfig.gif)
IDEA . , , - . , :
![](https://habrastorage.org/webt/pr/sf/pt/prsfpt9yrpowjbtuwciowtiavjk.gif)
JUnit. JUnit 3.8.1 , spring-boot-starter-test.
Maven Helper
, , . Maven Helper Vojtech Krasa. , mvn dependency:tree, .
, IDEA Community Edition IDEA, Maven .
, , pom.xml. Dependency Analyzer, .
![](https://habrastorage.org/webt/vj/ev/aa/vjevaapwskdrjaeg04ishwguy90.png)
( ). , . , .
Gradle
2019.2, IDEA Maven, Gradle. ! , Maven.
build.gradle Shift + Ctrl + Alt + U ( ⌥ + ⇧ + ⌘ + U Mac). → Diagrams → Show Dependencies.
当您创建应用程序时,正确构建依赖关系非常重要,因为具有困难且令人困惑的依赖关系的体系结构可能很难维护,扩展和修改。幸运的是,IDEA可以帮助解决结构依赖性矩阵,该矩阵提供了内部依赖性的有用图形表示。
除此之外,还必须确保还涵盖了外部依赖关系,这可以通过将依赖关系图用于您的依赖关系管理系统(例如Maven)来实现。