The maven dependency plugin is very handy when trying to deal with following questions:
- What are the external artifacts involved in a maven project. (dependency:resolve)
- Find out how an artifact is introduced into a project. (dependency:tree)
- In a multi modules project, how these modules denpend on each other? (dependency:tree –Dincludes=com.mypackage.*)
- Find out unnecessary dependencies in a maven project. (dependency:analyze)
To solve these puzzles, we need to know some typical usage of maven dependency plugin.
1. goal ‘resolve’
#list all dependencis mvn dependency:resolve
Output looks like below.
2. goal ‘tree’
# list dependencies tree. # can use –Dincludes=[groupId]:[artifactId]:[type]:[version], can use wildcard * # e.g -Dincludes=org.springframework*,org.apache* # list only package from spring and apache. mvn dependency:tree -Dincludes=org.springframework*
Output looks like below.
3. goal ‘analyze’
# List possible inmproper dependency. # 1.avoid ‘Used undeclared dependencies` # 2.'Unused declared dependencies` are not 100% reliable, cause of <provide> or <optional> # need to check manually mvn dependency:analyze
Output looks like below.
In above screenshot there are several suspicious dependencis may not be used at all. Then use “dependency:tree –Dincludes= org.springframework.boot:spring-boot-starter-web” to see how this dependency is introduced to the project.
0 comments:
Post a Comment