如何修复":编译测试Java"的执行任务失败?



我已经开始了一个使用Gradle的Java项目,其中我已经将必要的Spring Boot库导入到build.gradle中。当我构建这个项目时,它给了我以下错误:

错误

Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not find org.apache.httpcomponents:httpclient:1.2.5.
Required by:
project :
> Could not find org.apache.httpcomponents:httpclient:1.2.5.
Required by:
project : > io.rest-assured:rest-assured:4.1.2
> Could not find org.apache.httpcomponents:httpclient:1.2.5.
Required by:
project : > com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8 > com.microsoft.azure:azure-keyvault:0.9.3
project : > com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8 > com.microsoft.azure:azure-keyvault:0.9.3 > com.microsoft.azure:azure-core:0.9.3
> Could not find org.apache.httpcomponents:httpclient:1.2.5.
Required by:
project : > io.rest-assured:rest-assured:4.1.2 > org.apache.httpcomponents:httpmime:4.5.12
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

构建渐变

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

group 'AbtMainTestControl'
version '1.0-SNAPSHOT'
// Versioning of dependencies
wrapper.gradleVersion = '5.5.1'
def cucumberVersion = '4.7.1'
def junitVersion = '5.5.0'
def restVersion = '4.1.2'
def apacheDrillVersion = '1.17.0'

repositories {
jcenter()
mavenCentral()
}

dependencies {
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
compile group: 'com.opencsv', name: 'opencsv', version: '4.0'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '1.2.5'
// https://mvnrepository.com/artifact/org.apache.drill.tools/tools-parent
compile group: 'org.apache.drill.tools', name: 'tools-parent', version: "${apacheDrillVersion}", ext: 'pom'
// Cucumber Pretty Report Plugin
compile group: 'de.monochromata.cucumber', name: 'reporting-plugin', version: '3.0.9'

testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre8'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.7.0'

testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
testImplementation "io.rest-assured:rest-assured:${restVersion}"
testImplementation "io.rest-assured:json-path:${restVersion}"
testImplementation "io.rest-assured:json-schema-validator:${restVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junitVersion}"
implementation 'junit:junit:4.12'
}

configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath =  configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin',
'pretty',
'--glue',
'gradle.cucumber',
'src/test/resources/features',
]
}
}
}

test {
//useJUnitPlatform()
systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
}

在这种情况下,我已经取出了Spring Boot库,以便查看Build.Gradle文件中的问题所在

有人能推荐解决方案/帮助我解决这个问题吗?我们将非常感谢您的建议:(

httpclient-1.2.5-的版本看起来有点不对劲;最新版本为4.5.12。

最新更新