gpt4 book ai didi

java - gradle 插件使用代码中使用的旧版本/不同版本的 java 库

转载 作者:行者123 更新时间:2023-11-30 09:59:50 25 4
gpt4 key购买 nike

我想使用 swagger-gradle-plugin来自 swagger-core将我的 JAX-RS api 解析为 OpenApiDefinition 的项目。

现在我的问题是该插件使用版本 2.9.10 中的库 com.fasterxml.jackson.core:jackson-databind。我的项目也使用了这个库,但是版本是 2.10.0。现在,当我运行插件的解析任务时,我得到了一个 VerifyError,因为一个类被更改了。我已经开了一个issue在 github 上,但问题似乎是我的配置。

这是我的 gradle 构建文件:

plugins {
id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.10"
}

dependencies {
...
implementation 'io.swagger.core.v3:swagger-annotations:2.0.10'
implementation "com.fasterxml.jackson.core:jackson-databind:2.10.0"
implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0"
...
}

resolve {
outputFileName = 'lcapi'
outputFormat = 'YAML'
prettyPrint = 'TRUE'
classpath = sourceSets.test.runtimeClasspath
resourcePackages = ['com.example.lc.api']
resourceClasses = ['com.example.lc.api.LcRestController', 'com.example.lc.api.LcStateController']
outputPath = file("${project.projectDir}/src/main/resources")
}

最佳答案

有几种方法可以解决这个问题,但我认为最简单的方法是创建一个从您正在使用的配置扩展的新配置,但使用强制特定版本的 Jackson 的解析策略。它可能看起来像这样:

plugins {
id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.10"
}

configurations {
swagger {
extendsFrom runtimeClasspath
resolutionStrategy {
force 'com.fasterxml.jackson.core:jackson-databind:2.9.10'
force 'com.fasterxml.jackson.core:jackson-annotations:2.9.10'
}
}
}

dependencies {
implementation 'io.swagger.core.v3:swagger-annotations:2.0.10'
implementation "com.fasterxml.jackson.core:jackson-databind:2.10.0"
implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0"
// ...
}

resolve {
classpath = sourceSets.main.output + configurations.swagger
// ...
}

请注意,我让它使用普通的 runtimeClasspath 而不是您使用的 testRuntimeClasspath,因为我希望另一个只是尝试使其工作(您可能不希望测试资源渗入主要资源)。

关于java - gradle 插件使用代码中使用的旧版本/不同版本的 java 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58557741/

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