Last active
February 21, 2017 08:20
-
-
Save meistermeier/b506d225e6ce4b54b904028b767789e8 to your computer and use it in GitHub Desktop.
mvn dependency tree filtered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uses mvn dependency plugin to show why a certain dependency or dependencies are used | |
function mvnwhy() { | |
CANDIDATES=(`mvn dependency:list | grep $1 | awk '{print $2}'`) | |
for CANDIDATE in ${CANDIDATES[@]}; do | |
echo "Why $CANDIDATE?" | |
declare -a CANDIDATE_SEGMENTS | |
CANDIDATE_SEGMENTS=(`echo $CANDIDATE | awk 'BEGIN{FS=":"}{for (i=1; i<=2; i++) print $i}'`) | |
# this just works in zsh for bash use: DEPENDENCY=${CANDIDATE_SEGMENTS[0]}:${CANDIDATE_SEGMENTS[1]} | |
DEPENDENCY=${CANDIDATE_SEGMENTS[1]}:${CANDIDATE_SEGMENTS[2]} | |
# scans and shows dependency tree for every dep (this might get optimized later) | |
# background: no way found to get always the right line before the pattern matches | |
mvn dependency:tree -Dincludes=$DEPENDENCY | grep -B 1 "\\\-" | |
done | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# single match | |
mvnwhy com.jayway.jsonpath:json-path | |
# Output: | |
# Why com.jayway.jsonpath:json-path:jar:2.2.0:test? | |
# [INFO] com.meistermeier:rest-docs-sample:jar:0.0.1-SNAPSHOT | |
# [INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test | |
# [INFO] \- com.jayway.jsonpath:json-path:jar:2.2.0:test | |
# | |
# | |
# multi match | |
# call: | |
mvnwhy json | |
# Output: | |
# Why com.jayway.jsonpath:json-path:jar:2.2.0:test? | |
# [INFO] com.meistermeier:rest-docs-sample:jar:0.0.1-SNAPSHOT | |
# [INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test | |
# [INFO] \- com.jayway.jsonpath:json-path:jar:2.2.0:test | |
# Why org.json:json:jar:20140107:test? | |
# [INFO] com.meistermeier:rest-docs-sample:jar:0.0.1-SNAPSHOT | |
# [INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test | |
# [INFO] \- org.skyscreamer:jsonassert:jar:1.3.0:test | |
# [INFO] \- org.json:json:jar:20140107:test | |
# Why net.minidev:json-smart:jar:2.2.1:test? | |
# [INFO] com.meistermeier:rest-docs-sample:jar:0.0.1-SNAPSHOT | |
# [INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test | |
# [INFO] \- com.jayway.jsonpath:json-path:jar:2.2.0:test | |
# [INFO] \- net.minidev:json-smart:jar:2.2.1:test | |
# Why org.skyscreamer:jsonassert:jar:1.3.0:test? | |
# [INFO] com.meistermeier:rest-docs-sample:jar:0.0.1-SNAPSHOT | |
# [INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test | |
# [INFO] \- org.skyscreamer:jsonassert:jar:1.3.0:test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't have maven installed but the first
awk
may be replaced bycut -f2
(with the appropriate -d option) and the secondawk
could be replaced bycut -d: -f1-2
, making the whole for-part just two lines: