Gradle – Display project dependency
In this tutorial, we will show you how to display project dependencies with the Gradle build tool. Review a simple Spring MVC project dependencies.
dependencies {
compile 'org.slf4j:jcl-over-slf4j:1.7.12'
compile 'ch.qos.logback:logback-classic:1.1.3'
compile('org.springframework:spring-webmvc:4.1.6.RELEASE'){
exclude group: 'commons-logging', module: 'commons-logging'
}
compile 'org.hsqldb:hsqldb:2.3.2'
providedCompile 'javax.servlet:servlet-api:2.5'
}
P.S Tested with Gradle 2.4
1. gradle dependencies
Display project dependencies (direct and transitive for all configurations) in a tree format. This dependency report is very large, not much value to see this.
$ gradle dependencies
archives - Configuration for archive artifacts.
No dependencies
compile - Compile classpath for source set 'main'.
+--- org.slf4j:jcl-over-slf4j:1.7.12
| \--- org.slf4j:slf4j-api:1.7.12
+--- ch.qos.logback:logback-classic:1.1.3
| +--- ch.qos.logback:logback-core:1.1.3
| \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.12
+--- org.springframework:spring-webmvc:4.1.6.RELEASE
| +--- org.springframework:spring-beans:4.1.6.RELEASE
| | \--- org.springframework:spring-core:4.1.6.RELEASE
| +--- org.springframework:spring-context:4.1.6.RELEASE
| | +--- org.springframework:spring-aop:4.1.6.RELEASE
| | | +--- aopalliance:aopalliance:1.0
| | | +--- org.springframework:spring-beans:4.1.6.RELEASE (*)
| | | \--- org.springframework:spring-core:4.1.6.RELEASE
| | +--- org.springframework:spring-beans:4.1.6.RELEASE (*)
| | +--- org.springframework:spring-core:4.1.6.RELEASE
| | \--- org.springframework:spring-expression:4.1.6.RELEASE
| | \--- org.springframework:spring-core:4.1.6.RELEASE
| +--- org.springframework:spring-core:4.1.6.RELEASE
| +--- org.springframework:spring-expression:4.1.6.RELEASE (*)
| \--- org.springframework:spring-web:4.1.6.RELEASE
| +--- org.springframework:spring-aop:4.1.6.RELEASE (*)
| +--- org.springframework:spring-beans:4.1.6.RELEASE (*)
| +--- org.springframework:spring-context:4.1.6.RELEASE (*)
| \--- org.springframework:spring-core:4.1.6.RELEASE
+--- org.hsqldb:hsqldb:2.3.2
\--- javax.servlet:servlet-api:2.5
default - Configuration for default artifacts.
+--- org.slf4j:jcl-over-slf4j:1.7.12
| \--- org.slf4j:slf4j-api:1.7.12
+--- ch.qos.logback:logback-classic:1.1.3
| +--- ch.qos.logback:logback-core:1.1.3
| \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.12
...
providedCompile - Additional compile classpath for libraries that should not be part of the WAR arc
\--- javax.servlet:servlet-api:2.5
providedRuntime - Additional runtime classpath for libraries that should not be part of the WAR arc
\--- javax.servlet:servlet-api:2.5
runtime - Runtime classpath for source set 'main'.
+--- org.slf4j:jcl-over-slf4j:1.7.12
| \--- org.slf4j:slf4j-api:1.7.12
+--- ch.qos.logback:logback-classic:1.1.3
| +--- ch.qos.logback:logback-core:1.1.3
| \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.12
...
testCompile - Compile classpath for source set 'test'.
+--- org.slf4j:jcl-over-slf4j:1.7.12
| \--- org.slf4j:slf4j-api:1.7.12
+--- ch.qos.logback:logback-classic:1.1.3
| +--- ch.qos.logback:logback-core:1.1.3
| \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.12
...
... this report can be very large
2. gradle dependencies –configuration
Normally, we just need to see the dependencies report for a particular configuration. In below example, it displays the dependency report for “runtime” configuration only.
$ gradle dependencies --configuration runtime
runtime - Runtime classpath for source set 'main'.
+--- org.slf4j:jcl-over-slf4j:1.7.12
| \--- org.slf4j:slf4j-api:1.7.12
+--- ch.qos.logback:logback-classic:1.1.3
| +--- ch.qos.logback:logback-core:1.1.3
| \--- org.slf4j:slf4j-api:1.7.7 -> 1.7.12
+--- org.springframework:spring-webmvc:4.1.6.RELEASE
| +--- org.springframework:spring-beans:4.1.6.RELEASE
| | \--- org.springframework:spring-core:4.1.6.RELEASE
| +--- org.springframework:spring-context:4.1.6.RELEASE
| | +--- org.springframework:spring-aop:4.1.6.RELEASE
| | | +--- aopalliance:aopalliance:1.0
| | | +--- org.springframework:spring-beans:4.1.6.RELEASE (*)
| | | \--- org.springframework:spring-core:4.1.6.RELEASE
| | +--- org.springframework:spring-beans:4.1.6.RELEASE (*)
| | +--- org.springframework:spring-core:4.1.6.RELEASE
| | \--- org.springframework:spring-expression:4.1.6.RELEASE
| | \--- org.springframework:spring-core:4.1.6.RELEASE
| +--- org.springframework:spring-core:4.1.6.RELEASE
| +--- org.springframework:spring-expression:4.1.6.RELEASE (*)
| \--- org.springframework:spring-web:4.1.6.RELEASE
| +--- org.springframework:spring-aop:4.1.6.RELEASE (*)
| +--- org.springframework:spring-beans:4.1.6.RELEASE (*)
| +--- org.springframework:spring-context:4.1.6.RELEASE (*)
| \--- org.springframework:spring-core:4.1.6.RELEASE
+--- org.hsqldb:hsqldb:2.3.2
\--- javax.servlet:servlet-api:2.5
(*) - dependencies omitted (listed previously)
3. gradle dependencyInsight
This “insight” let you find out the relationship for a particular dependency.
3.1 In below example, both jcl-over-slf4j
and logback-classic
depends on slf4j-api
, but there is a version conflict, and Gradle pick up the latest version slf4j-api:1.7.12
.
$ gradle dependencyInsight --dependency slf4j-api --configuration compile
org.slf4j:slf4j-api:1.7.12 (conflict resolution)
\--- org.slf4j:jcl-over-slf4j:1.7.12
\--- compile
org.slf4j:slf4j-api:1.7.7 -> 1.7.12
\--- ch.qos.logback:logback-classic:1.1.3
\--- compile
3.2 Yet another example, declares a Jackson 2.8.7
, but Gradle picks the latest Jackson 2.9.0.pr1
dependencies {
compile "com.fasterxml.jackson.core:jackson-databind:2.8.7"
compile ('com.maxmind.geoip2:geoip2:2.8.0') //depends on 2.9.0.pr1
}
$ gradle :dependencyInsight --configuration compile --dependency jackson-databind
:core:dependencyInsight
com.fasterxml.jackson.core:jackson-databind:2.9.0.pr1 (conflict resolution)
com.fasterxml.jackson.core:jackson-databind:2.8.2 -> 2.9.0.pr1
\--- com.maxmind.geoip2:geoip2:2.8.0
\--- compile
com.fasterxml.jackson.core:jackson-databind:2.8.7 -> 2.9.0.pr1
\--- compile
com.fasterxml.jackson.core:jackson-databind:[2.7.0,) -> 2.9.0.pr1
\--- com.maxmind.db:maxmind-db:1.2.1
\--- com.maxmind.geoip2:geoip2:2.8.0
\--- compile
4. gradle dependencies multi-project
Review a multi-project example.
include 'core', 'crawler', 'whois', 'web','analyzer','security'
To display the dependencies report for a subproject :
$ gradle {subproject}:dependencies
For example, display dependencies report for a subproject core
:
$ gradle core:dependencies
$ gradle core:dependencies --configuration compile
$ gradle core:dependencyInsight --dependency slf4j-api --configuration compile
This doesnt show up dependency added with fileTree
Do you know how to display the “dependency added with fileTree”?
This page would be a lot more useful if it also included examples of the dependencies that do NOT show up in report – for instance “files” or “fileTree” ones.
Do you know how to display it?