GradleとJUnitの例
Gradleでは、次のようにJUnitの依存関係を宣言できます。
build.gradle
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.12'
}
デフォルトでは、JUnitには `hamcrest-core`のバンドル版が付属しています
$ gradle dependencies --configuration testCompile
testCompile - Compile classpath for source set 'test'.
\--- junit:junit:4.12
\--- org.hamcrest:hamcrest-core:1.3
1. JUnit Hamcrest
通常は、便利な
hamcrest-library`ライブラリが必要です。そのため、JUnitでバンドルされた
hamcrest-core`のコピーを除外し、元の `hamcrest-core`ライブラリを含めてください。更新された `pom.xml`をもう一度見直してください。
build.gradle
apply plugin: 'java'
dependencies {
testCompile('junit:junit:4.12'){
exclude group: 'org.hamcrest'
}
testCompile 'org.hamcrest:hamcrest-library:1.3'
}
依存関係をもう一度見直してください。
$ gradle dependencies --configuration testCompile
testCompile - Compile classpath for source set 'test'.
+--- junit:junit:4.12
\--- org.hamcrest:hamcrest-library:1.3
\--- org.hamcrest:hamcrest-core:1.3
参考文献
-
リンク://gradle/gradle-display-project-dependency/[Gradle display
プロジェクトの依存関係]。
https://github.com/junit-team/junit4/wiki/Use-with-Gradle
[JUnit – 使用
Gradleと一緒に]