Gradle – プロジェクトの依存関係を表示する
このチュートリアルでは、Gradleビルドツールでプロジェクトの依存関係を表示する方法を説明します。単純なSpring MVCプロジェクトの依存関係を見直してください。
build.gradle
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 Gradle 2.4
でテスト済み
1. gradle依存関係
プロジェクト依存関係をツリー形式で表示します(すべての構成に対して直接的かつ推移的)。この依存関係レポートは非常に大きく、これを見る価値はあまりありません。
ターミナル
$ 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 - WARアークの一部ではないライブラリ用の追加コンパイルクラスパス\ --- javax.servlet:servlet-api:2.5 providedRuntime - WARアークの一部ではないライブラリ用の追加ランタイムクラスパス\ --- javax.servlet:servlet-api:2.5 runtime - ソースセット '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 - ソースセット '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依存関係 – 設定
通常、特定の構成の依存関係レポートを表示するだけです。以下の例では、 “ランタイム”設定のみの依存関係レポートを表示します。
ターミナル
$ 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
この「洞察」は、特定の依存関係の関係を見つけることができます。
3.1以下の例では、
jcl-over-slf4j`と
logback-classic`の両方が
slf4j-api`に依存していますが、バージョンの競合があり、Gradleは最新バージョン
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さらに別の例では、「Jackson 2.8.7」と宣言しているが、Gradleは最新の
Jackson 2.9.0.pr1
build.gradle
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依存関係のマルチプロジェクト
マルチプロジェクトの例を見直してください。
settings.gradle
include 'core', 'crawler', 'whois', 'web','analyzer','security'
サブプロジェクトの依存関係レポートを表示するには:
$ gradle {subproject}:dependencies
たとえば、依存関係の表示は、サブプロジェクト `core`のレポートです。
$ gradle core:dependencies $ gradle core:dependencies --configuration compile $ gradle core:dependencyInsight --dependency slf4j-api --configuration compile
参考文献
-
https://docs.gradle.org/current/userguide/userguide
single.html#sec:listing
dependencies[Gradle
ユーザーガイド – リストの依存関係]