我试图用OkHttp和Cucumber在静态编程语言中设置一个Spring启动项目,并且在运行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.
还有build 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,我如何将其翻译为kotlinbuild.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))
}
}
我和你一样有同样的问题,我会这样翻译建议的解决方案:
configurations.forEach {
if (it.name.contains("kapt") || it.name.contains("wire") {
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, "java-runtime"))
}
}
但是这个修复程序并没有为我解决这个问题,因为我没有kapt
和wire
的任何配置。
看起来这一行是关键:
> Could not resolve all files for configuration ':cucumberRuntime'.
在https://github.com/square/okio/issues/647,这是:
> Could not resolve all task dependencies for configuration ':main:kapt'.
所以他们用“卡普”作为名字。Bonkyin,他需要用Monkey:
configurations.all {
if (name.contains("cucumberRuntime")) {
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, Usage.JAVA_RUNTIME))
}
}
在我的例子中,这个名字对我来说很有用:“productionRuntimeClasspath”
我有一个Spring Boot应用程序,以Kotlin为语言,Gradle为构建系统。所以基本上,我试图用应用程序源代码和依赖项构建一个胖jar,可以使用Java命令行工具运行。 Gradle构建脚本: 如果我使用gradle命令运行项目,那么它运行正常。但是当我构建jar并尝试ti运行时,它会抱怨以下错误:- 应用.kt:- 不知道我到底哪里做错了什么。
我试图添加库暴露到我的项目。所以,它把我带到了bintray页面,在那里它说使用。我打开我的文件并将该文件放入段: IntelliJ自动构建它,我得到以下错误 警告:根项目“DB表到Orm”:无法生成Kotlin项目配置详细信息:java。朗。反思。InvocationTargetException:null由:org引起。格拉德尔。应用程序编程接口。人工制品ResolveException:无法
为了描述Gradle构建脚本,我们可以通过< code>build.gradle.kts文件使用Kotlin。在< code>dependencies和build 部分全局定义要使用的Kotlin版本是一个常见的问题(在给定的情况下使用不同的版本是相当罕见的)。 请考虑以下代码 (Gradle 4.3.1): 如您所见,kotlin(在本例中为1.2.30)定义了两次:和,它们通常没有区别。由于D
构建失败,类路径错误: : 构建文件是工作构建的直接副本。上下文是从Kotlin脚本Gradle开始的。据我所知,这个剧本应该不错。 请注意,我没有使用intelli-J,这完全是使用Kotlin脚本Gradle的CLI。 也许这很简单,比如“插件”和“插件”。。。
正如标题所说,我正在尝试将Java和Kotlin混合在一个项目中。这里有一个很好的例子。混合java kotlin hello world。除了kotlin在src/main/Java/somepackage/SomeClass中找不到我的任何Java类之外,所有的东西都正常工作。Java语言 这是什么原因? 我的身材。gradle看起来像这样 而不是开始尝试在更大的项目上实现这一点。我试图通过创
如图所示,https://stackoverflow.com/a/16639438/8949356,在Java中,当声明的类是公共类时,可以重写其函数 但是我想知道如何用静态编程语言编写完全相同的代码,我已经尝试了很多,但没有找到任何关于这个主题的东西。我可以在Java中去做这件事,但我的其余代码是用静态编程语言编写的,而且我不能一直带着这种怀疑;静态编程语言对我来说是一个很好的工具,我想学习它。