在 testCompileJava 期间找不到 powermock-api-support-sources.jar

Could not find powermock-api-support-sources.jar during testCompileJava

在我的项目中进行 运行 测试时,出现以下错误。我们不确定为什么构建要查找源 jar 文件。

04:15:21 > Task :clean UP-TO-DATE
04:15:28 > Task :compileJava FROM-CACHE
04:15:28 > Task :processResources
04:15:28 > Task :classes
04:15:31 > Task :bootWar
04:15:31 > Task :war SKIPPED
04:15:31 > Task :assemble
04:15:32 > Task :checkstyleMain FROM-CACHE
04:15:32 > Task :compileTestJava FAILED
04:15:32 
04:15:32 FAILURE: Build failed with an exception.
04:15:32 
04:15:32 * What went wrong:
04:15:32 
Execution failed for task ':compileTestJava'.
04:15:32 > Could not resolve all files for configuration ':testCompileClasspath'.
04:15:32    > Could not find powermock-api-support-sources.jar (org.powermock:powermock-api-support:2.0.2).
04:15:32      Searched in the following locations:
04:15:32          file:/data/jenkins/.m2/repository/org/powermock/powermock-api-support/2.0.2/powermock-api-support-2.0.2-sources.jar
04:15:32    > Could not find powermock-core-sources.jar (org.powermock:powermock-core:2.0.2).
04:15:32      Searched in the following locations:
04:15:32          file:/data/jenkins/.m2/repository/org/powermock/powermock-core/2.0.2/powermock-core-2.0.2-sources.jar
04:15:32    > Could not find powermock-reflect-sources.jar (org.powermock:powermock-reflect:2.0.2).
04:15:32      Searched in the following locations:
04:15:32          file:/data/jenkins/.m2/repository/org/powermock/powermock-reflect/2.0.2/powermock-reflect-2.0.2-sources.jar
04:15:32 
04:15:32 * Try:
04:15:32 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

我正在复制 dependencies.gradle 片段


    compile 'org.apache.maven.plugins:maven-surefire-plugin:2.22.0'
    testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.0"
    testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0'
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.0"
    testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
    testImplementation 'org.mockito:mockito-junit-jupiter:2.23.4'
    testCompile group: 'org.powermock', name: 'powermock-mockito-release-full', version: '1.6.4'
    testCompile group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
    testCompile group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
    testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'

我正在使用 java 11、springboot 2.0.5 和 junit 5

经过反复试验,我们发现这是因为其中一个 powermock 库仍然引用 junit 4,并且它添加了一些不需要的依赖项。因此,我们清理了测试依赖项,也避免了具有 PowerMockRunner 的库。这解决了这个问题。请在下面找到最新的 dependencies.gradle 片段,

 testCompile(group: 'org.springframework.boot', name: 'spring-boot-test', version: springBootVersion) {
     exclude (module: 'junit')
 }
 testCompile group: 'org.springframework', name: 'spring-test', version: springVersion
 testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion) {
     exclude(module: 'commons-logging')
 }

 compile 'org.apache.maven.plugins:maven-surefire-plugin:2.22.0'
 testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.2'
 testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.3.2'
 testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.3.2'

 testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
 testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'