简体   繁体   English

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

[英]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.

相关问题 如何使用不同版本的Java执行Gradle插件 - How to execute gradle plugin with different version of java 如何允许用户更改Gradle中插件使用的库版本? - How to allow user to change the version of the library which is used by a plugin in Gradle? Java / Maven如何使用使用项目中已使用的另一个依赖项的旧版本的依赖项 - Java/Maven how to use a dependency that uses an older version of another dependency that is already used in the project 下载旧版本的SonarQube Java插件 - Download Older Version of SonarQube Java Plugin 我可以用较新的JDK用ant编译Java较旧版本的Java,以便在编译使用较新API的代码时生成输出吗? - Can i compile java for an older Java version with ant with a newer JDK so it generates output when it compiles code that uses the newer API? 依赖项取决于项目中已使用的旧版本库 - A dependency depends on older version of a library already used in the project Java-编写旧版本忽略的代码 - Java - Write code that older version ignore Java Eclipse运行我的代码的旧版本 - Java eclipse runs older version of my code 如何更改Eclipse SpringSource插件使用的Gradle版本? - How do I change the Gradle version the Eclipse SpringSource plugin uses? 确定 gradle 构建中使用的 java 版本 - determining java version used in gradle build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM