我大致有以下设置:
test-utils/build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
dependencies {
compile ('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.mockito'
exclude group: 'org.hamcrest'
}
compile 'org.mockito:mockito-core:2.0.41-beta'
compile 'org.assertj:assertj-core:3.3.0'
}
main/build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
dependencies {
testCompile project(':test-utils')
}
但由于某种原因,似乎spring boot插件强制mockito版本回到1.x:
# ./gradlew :main:dependencies --configuration=testCompile
testCompile - Compile classpath for source set 'test'.
+--- project :test-utils
+--- org.springframework.boot:spring-boot-starter-test: -> 1.3.1.RELEASE
| +--- junit:junit:4.12
| +--- org.springframework:spring-core:4.2.4.RELEASE
| \--- org.springframework:spring-test:4.2.4.RELEASE
| \--- org.springframework:spring-core:4.2.4.RELEASE
+--- org.mockito:mockito-core:2.0.41-beta -> 1.10.19
| +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
| \--- org.objenesis:objenesis:2.1
\--- org.assertj:assertj-core:3.3.0
如果我将弹簧启动插件从等式中取出,事情就会按预期工作:
# ./gradlew :main:dependencies --configuration=testCompile
testCompile - Compile classpath for source set 'test'.
+--- project :test-utils
+--- org.springframework:spring-core:4.2.4.RELEASE (*)
+--- org.springframework:spring-test:4.2.4.RELEASE
| \--- org.springframework:spring-core:4.2.4.RELEASE (*)
+--- junit:junit:4.12
+--- org.mockito:mockito-core:2.0.41-beta
| +--- net.bytebuddy:byte-buddy:1.0.2
| \--- org.objenesis:objenesis:2.1
\--- org.assertj:assertj-core:3.3.0
春季启动插件究竟做了什么,我怎么能告诉它不要?
答案 0 :(得分:4)
您的main
项目已应用Spring Boot的插件,因此它使用了Spring Boot的依赖关系管理。这意味着,默认情况下,它将使用Spring Boot的首选Mockito版本,而不管test-utils
中指定的版本。
作为described in the documentation,您可以通过设置相关属性来覆盖Spring Boot管理的依赖项的版本。对于Mockito,该属性为mockito.version
。将以下内容添加到main
项目中:
ext['mockito.version'] = '2.0.41-beta'
答案 1 :(得分:0)
我认为您可以使用配置设置来强制版本
allprojects {
configurations.all {
resolutionStrategy { rs ->
rs.force "org.mockito:mockito-core:2.0.41-beta"
}
}
}