我正在尝试使用spring-test-mvc在我的小应用程序中测试控制器 . 因为我使用gradle作为构建工具,所以我将依赖项添加到它:
testCompile 'org.springframework:spring-test-mvc:1.0.0.M1'
它成功检索spring-test-mvc,并编译测试 . 但执行测试失败,因为它似乎不包括像mvc test这样的瞬态依赖 .
其中抱怨没有找到
org.springframework.mock.web.MockHttpServletRequest
这是spring-test.jar的一部分,它包含在spring-test-mvc的pom.xml中作为依赖项https://github.com/SpringSource/spring-test-mvc/blob/master/pom.xml
我可以通过在构建文件中明确地包含依赖项来解决该问题:
testCompile 'org.springframework:spring-test:3.1.1.RELEASE'
但它只会被下一个问题所取代 . 我试图明确要求瞬态依赖:
testCompile ('org.springframework:spring-test-mvc:1.0.0.M1') {
transitive = true
}
但这并不能改变任何事情 .
所以问题是:如何让Gradle在类路径中包含传递依赖项 .
注意:传递依赖性似乎在测试之外工作正常 .
1 回答
这是POM的一个问题 . http://repo.springsource.org/libs-milestone/org/springframework/spring-test-mvc/1.0.0.M1/spring-test-mvc-1.0.0.M1.pom未声明任何依赖项 .