Gradle maven bom 的 7.0 版本目录

Gradle 7.0 Version Catalog for maven bom

我已经发布了 maven bom 并将其导入到顶层 build.gradle.kts 为:

allProjects {
  dependencies {
        implementation(platform("com.example:some-dependencies:1.2.3"))
    }
}

然后在libs.versions.toml:

[libraries]
some-bom = { group = "com.example", name="some-dependencies", version="1.2.3" }

当我将第一个代码示例更改为:

allProjects {
  dependencies {
        implementation(platform(libs.some.bom))
    }
}

我得到:

Could not resolve: javax.xml.bind:jaxb-api
Could not resolve: org.springframework.boot:spring-boot-starter-test
...

有没有什么办法可以用Gradle7版本的boms目录?

就我而言,它很管用。我正在从事 Android 项目,我的脚本如下所示:

//libs.versions.toml
[libraries]
deps_okhttp_bom = "com.squareup.okhttp3:okhttp-bom:4.9.1"
deps_okhttp_lib = { module  ="com.squareup.okhttp3:okhttp" }
deps_okhttp_logging_interceptor = { module= "com.squareup.okhttp3:logging-interceptor"}

//build.xml
dependencies {
  implementation platform(libs.deps.okhttp.bom)
  implementation libs.deps.okhttp.lib
  implementation libs.deps.okhttp.logging.interceptor
}

在您的示例中,您刚刚添加了 BOM 的依赖项。但由于 BOM 只是一个规范 sheet,它描述了每个库的版本,因此您需要为特定库添加依赖项。