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. Gradle + JUnit + Hamcrest
通常、便利なhamcrest-library
ライブラリが必要なので、hamcrest-core
のJUnitバンドルコピーを除外し、元の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