我希望向我的使用 gradle 的项目添加测试依赖项。我只需要让 gradle 下载依赖 jar,这样我就可以导入部分包。我需要的是以下包:
import org.springframework.security.test.*
所以我编辑了我的 gradle 文件以包含
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
runtime('org.hsqldb:hsqldb')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test') // This is what I added to try and download the new dependency
}
进入这个后我尝试构建项目。不幸的是,这不起作用,我不能
import org.springframework.security.test.*
然后我跑了 gradlew test
这实际上取得了一些成功并表明:Download https://repo1.maven.org/maven2/org/springframework/security/spring-security-test/4.0.3.RELEASE/spring-security-test-4.0.3.RELEASE.pom
Download https://repo1.maven.org/maven2/org/springframework/security/spring-security-test/4.0.3.RELEASE/spring-security-test-4.0.3.RELEASE.jar
虽然我不知道它下载到哪里。导航至
$HOME/.gradle/caches/modules-2/files-2.1/org.springframework.security
我看不到下载包的任何迹象(并且 Idea 在其外部库中无法识别它)。运行 gradle build --refresh-dependencies
似乎没有用。任何帮助将不胜感激。
Closes SO question I could find
最佳答案
我遇到了同样的问题,如果依赖项中包含特定版本,它会起作用,例如:
testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '5.1.6.RELEASE'
关于java - Gradle 未下载测试依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36828997/