gradle平台依赖与java库

h9vpoimq  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(591)

我们有两个公共库,它们使用java库gradle插件,并通过平台依赖于micronaut的bom。两个项目都使用gradle6.6.1,这是撰写本文时的最新版本。
图书馆 build.gradle ```
plugins {
id "java-library"
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {

annotationProcessor (
    platform("io.micronaut:micronaut-bom:$micronautVersion"),
    "io.micronaut:micronaut-inject-java"
)

implementation(
    platform("io.micronaut:micronaut-bom:$micronautVersion"),
    "io.micronaut:micronaut-inject"
)

testAnnotationProcessor(
    enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"),
    "io.micronaut:micronaut-inject-java"
)

testImplementation(
    enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"),
    "io.micronaut:micronaut-runtime",
    "io.micronaut:micronaut-http-server-netty",
    "io.micronaut:micronaut-http-client"
)

}

当我尝试在一个应用程序中使用我的库时,它使用了application gradle插件,并且对micronaut的bom有平台依赖性,我得到一个错误,说它不能解析库使用的micronaut bom。但它永远无法解决这种依赖关系,因为它是一个bom,而不是一个库。
应用 `build.gradle` ```
plugins {
    id "application"
    id "java"
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    implementation(
        "my.group:library:${libraryVersion}",

        platform("io.micronaut:micronaut-bom:${micronautVersion}"),
        "io.micronaut:micronaut-http-client",
        "io.micronaut:micronaut-http-server-netty",
        "io.micronaut:micronaut-inject",
        "io.micronaut:micronaut-management",
        "io.micronaut:micronaut-runtime",
        "io.micronaut:micronaut-validation"
    )
}

然后我得到以下错误。

Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve io.micronaut:micronaut-bom:2.0.1.
Required by:
    project : > my.group:library:11.0.0-SNAPSHOT
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: No matching variant of io.micronaut:micronaut-bom:2.0.1 was found. The consumer was configured to find a runtime of a library compatible with Java 14, packaged as a jar, and its dependencies declared externally but:
  - Variant 'apiElements' capability io.micronaut:micronaut-bom:2.0.1:
      - Incompatible because this component declares an API of a platform and the consumer needed a runtime of a library
      - Other compatible attributes:
          - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
          - Doesn't say anything about its target Java version (required compatibility with Java 14)
          - Doesn't say anything about its elements (required them packaged as a jar)

我试着阅读了gradle文档中关于变体选择的内容,但这对我来说并没有多大意义。有人知道我需要如何声明依赖项才能使其工作吗?这似乎是一件很琐碎的事情,但我没有发现任何关于这个。。。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题