首页 > 解决方案 > 使用带有 java9+ 的 gradle 的自动模块的依赖性问题

问题描述

我正在尝试将旧项目迁移到 java 11。

dependencies {
    implementation ('com.google.code.findbugs:jsr305:3.0.2')
    implementation ('javax.xml.ws:jaxws-api:2.3.1')
}

这些都包括注释,其他库抱怨它们是这样的:

error: module jsr305 reads package javax.annotation from both java.annotation and jsr305
error: module vboxjws reads package javax.annotation from both java.annotation and jsr305
error: module io.sentry reads package javax.annotation from both java.annotation and jsr305
error: module com.fasterxml.jackson.databind reads package javax.annotation from both java.annotation and jsr305
error: module com.fasterxml.jackson.dataformat.yaml reads package javax.annotation from both java.annotation and jsr305
error: module com.fasterxml.jackson.annotation reads package javax.annotation from both java.annotation and jsr305

我找到的解决方案是3:

1

configurations.all {
    exclude module: 'javax.annotation-api'
}

2

configurations.all {
resolutionStrategy {
        preferProjectModules()
        dependencySubstitution {

            substitute(module("javax.annotation:javax.annotation-api")).with(module("com.google.code.findbugs:jsr305:3.0.2"))

}}}

3

implementation ('javax.xml.ws:jaxws-api:2.3.1') {
        exclude group: 'javax.annotation', module: 'javax.annotation-api'
    }

他们都导致另一个错误:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module java.annotation not found, required by java.xml.ws

这是一个例子,我在项目中有大约 20 个库并且有多个冲突,我读到另一种选择是手动将所有 jar 合并为一个,但我真的很想避免这种情况。有没有办法在gradle中解决这个问题?

标签: javagradlejava-11

解决方案


推荐阅读