gpt4 book ai didi

java - Gradle Kotlin, cucumber 和OKHttp

转载 作者:行者123 更新时间:2023-12-02 12:57:12 30 4
gpt4 key购买 nike

我正在尝试使用OkHttp和Cucumber在Kotlin中设置一个Spring Boot项目,并在运行Cucumber任务时遇到以下错误。我该如何解决?

Execution failed for task ':cucumber'.
> Could not resolve all files for configuration ':cucumberRuntime'.
> Could not resolve com.squareup.okio:okio:2.4.1.
Required by:
project : > com.squareup.okhttp3:okhttp:4.3.1
> Cannot choose between the following variants of com.squareup.okio:okio:2.4.1:
- jvm-api
- jvm-runtime
- metadata-api
All of them match the consumer attributes:
- Variant 'jvm-api' capability com.squareup.okio:okio:2.4.1:
- Unmatched attributes:
- Found org.gradle.libraryelements 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'java-api' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
- Variant 'jvm-runtime' capability com.squareup.okio:okio:2.4.1:
- Unmatched attributes:
- Found org.gradle.libraryelements 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'java-runtime' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
- Variant 'metadata-api' capability com.squareup.okio:okio:2.4.1:
- Unmatched attributes:
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'common' but wasn't required.


和构建gradle kts片段
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "2.2.5.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.61"
kotlin("plugin.spring") version "1.3.61"
}

group = "com.foo"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

val developmentOnly by configurations.creating
configurations {
runtimeClasspath {
extendsFrom(developmentOnly)
}
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
annotationProcessor("org.projectlombok:lombok")

implementation("com.squareup.okhttp3:okhttp:4.3.1")
implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:6.0.1")
runtimeOnly("com.graphql-java-kickstart:graphiql-spring-boot-starter:6.0.1")
runtimeOnly("com.graphql-java-kickstart:voyager-spring-boot-starter:6.0.1")

testImplementation("io.cucumber:cucumber-java8:5.4.0")
testImplementation("io.cucumber:cucumber-junit:5.4.0")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}

val cucumberRuntime by configurations.creating {
extendsFrom(configurations["testImplementation"])
}

task("cucumber") {
dependsOn("assemble")
dependsOn("compileTestJava")
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = cucumberRuntime + sourceSets.main.get().output + sourceSets.test.get().output
args = listOf("--plugin", "pretty", "--glue", "gradle.cucumber", "src/test/resources")
}
}
}



我看到了这个错误 https://github.com/square/okio/issues/647,看起来像是它,并且是对该build.gradle的修复,如何将其翻译为kotlin以获取build.gradle.kts?
subprojects { subProject ->
...

configurations.all { configuration ->
// Workaround for kapt bug with MPP dependencies
// https://youtrack.jetbrains.com/issue/KT-31641
// https://youtrack.jetbrains.com/issue/KT-33206
if (name.contains('kapt') || name.contains("wire")) {
attributes.attribute(Usage.USAGE_ATTRIBUTE, subProject.objects.named(Usage.class, Usage.JAVA_RUNTIME))
}
}

最佳答案

看起来这行是关键:

 > Could not resolve all files for configuration ':cucumberRuntime'.

In https://github.com/square/okio/issues/647, this is:

> Could not resolve all task dependencies for configuration ':main:kapt'.

So they used "kapt" as the name. In MonkeyBonkey's case, he will need to use:

configurations.all {
if (name.contains("cucumberRuntime")) {
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, Usage.JAVA_RUNTIME))
}
}
在我的情况下,这为我起作用了另一个名称:“production RuntimeClasspath”

关于java - Gradle Kotlin, cucumber 和OKHttp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60457292/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com