在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