[英]gradle plugin uses a older/different version of a java library used in the code
I want to use the swagger-gradle-plugin from the swagger-core project to resolve my JAX-RS api to a OpenApiDefinition.我想使用swagger-core项目中的swagger-gradle-plugin将我的 JAX-RS api 解析为 OpenApiDefinition。
Now my problem ist that the plugin uses the library com.fasterxml.jackson.core:jackson-databind
in the version 2.9.10
.现在我的问题是插件在版本
2.9.10
中使用库com.fasterxml.jackson.core:jackson-databind
。 My project also uses this library but in the verson 2.10.0
.我的项目也使用这个库,但在
2.10.0
版本中。 Now when I run the resolve task of the plugin I get a VerifyError
because a class was changed.现在,当我运行插件的解析任务时,我得到了一个
VerifyError
,因为 class 已更改。 I already opened a issue on github but the problem seems to be my configuration.我已经在 github 上打开了一个问题,但问题似乎是我的配置。
This is my gradle build file:这是我的 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")
}
There are a few ways you can get around it, but I think the simplest one is to create a new configuration that extends from the one you are using, but with a resolution strategy that forces the particular version of Jackson.有几种方法可以绕过它,但我认为最简单的一种是创建一个从您正在使用的配置扩展的新配置,但使用强制特定版本的 Jackson 的分辨率策略。 It could look like this:
它可能看起来像这样:
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
// ...
}
Note that I made it use the normal runtimeClasspath
instead of the testRuntimeClasspath
that you were using, as I expect the other one was just an attempt at making it work (you probably don't want test resources bleeding into the main resources).请注意,我使它使用正常的
runtimeClasspath
而不是您正在使用的testRuntimeClasspath
,因为我希望另一个只是尝试使其工作(您可能不希望测试资源渗入主要资源)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.