본문 바로가기

카테고리 없음

[Scala]dependency tree 확인할 수 있는 유용한 Plugin : sbt-dependency-graph

Java에서 디펜던시 관리 도구로 maven 또는 gradle을 주로 사용합니다. 반면 Scala에서는 SBT를 사용하여 디펜던시를 관리하는데요. 디펜던시를 관리하다보면 일부 library가 하위 library를 추가로 import하면서 꼬이는 경우(동일 library에 n개 이상의 version 동시 import)가 있습니다.

 

이러한 경우 dependency를 찾기 매우 난감한데요. 이때 사용할 수 있는 좋은 plugin이 있어 소개드립니다.

 

sbt-dependecy-graph

※ 이 plugin은 sbt 1.3.x 이하, 0.13.10이상의 sbt에서만 동작합니다.

Github url : https://github.com/jrudolph/sbt-dependency-graph

 

jrudolph/sbt-dependency-graph

sbt plugin to create a dependency graph for your project - jrudolph/sbt-dependency-graph

github.com

사용방법

Project 하위에 project/plugins.sbt에 아래 code를 추가합니다.

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")

자주사용하는 명령어 리스트:

dependencyTree: sbt command창에서 ASCII로 dependency를 보여줍니다.
dependencyBrowseGraph: browser에서 dependency를 graph로 보여줍니다.
dependencyBrowseTree: browser에서 dependency를 Tree형태로 보여줍니다.

 

추가 명령어 리스트:
dependencyList: Shows a flat list of all transitive - dependencies on the sbt console (sorted by - organization and name)
- whatDependsOn [organization] [module [revision]? :Find - out what depends on an artifact. Shows a reverse - dependency tree for the selected module. The <- revision> argument is optional.
dependencyLicenseInfo: show dependencies grouped by - declared license
dependencyStats: Shows a table with each module a row with - (transitive) Jar sizes and number of dependencies
dependencyGraphMl: Generates a .graphml file with the - project's dependencies to target/- dependencies-.graphml. Use e.g. yEd to format - the graph to your needs.
dependencyDot: Generates a .dot file with the project's - dependencies to target/dependencies-.dot. Use - graphviz to render it to your preferred graphic format.
dependencyGraph: Shows an ASCII graph of the project's - dependencies on the sbt console (only supported on sbt - 0.13)
ivyReport: Lets ivy generate the resolution report for you project. Use show ivyReport for the filename of the generated report

 

아래 명령어들은 file 저장을 지원합니다.


dependencyTree
dependencyList
dependencyStats
dependencyLicenseInfo

디펜던시에 대한 구성도를 file로 저장하려면 아래와 같이 sbt명령어를 수행합니다.

<config>:<task>::toFile <filename> [-f|--force]

 

사용 예시

sbt> dependencyTree
[info] default:scala-study_2.12:0.1.0-SNAPSHOT [S]
[info] wonyoung-app:main_project_2.11:1.0.0 [S]
[info]   +-ch.qos.logback:logback-classic:1.2.3
[info]   | +-ch.qos.logback:logback-core:1.2.3
[info]   | 
[info]   +-com.iheart:ficus_2.11:1.2.3
[info]   +-com.novus:salat_2.11:1.9.9
[info]   | +-com.novus:salat-core_2.11:1.9.9
[info]   | | +-com.novus:salat-util_2.11:1.9.9
[info]   | | | +-org.scala-lang:scalap:2.11.8
[info]   | | | | +-org.scala-lang:scala-compiler:2.11.8
[info]   | | | |   +-org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4
[info]   | | | |   +-org.scala-lang.modules:scala-xml_2.11:1.0.4 (evicted by:..
[info]   | | | |   +-org.scala-lang.modules:scala-xml_2.11:1.0.5
[info]   | | | |   +-org.scala-lang:scala-reflect:2.11.8
[info]   | | | |   
[info]   | | | +-org.slf4j:slf4j-api:1.7.2 (evicted by: 1.7.25)

dependencyTree는 sbt command창에서 ascii로 Tree를 만들어 보여줍니다. 간단한 디펜던시를 찾을때 유용합니다.

sbt> dependencyBrowseGraph

dependencyBrowseGraph는 browser로 디펜던시 그래프를 그려보여주기 때문에 복잡한 dependency를 파악할때 한눈에 보기 좋습니다.

반응형