将bundle导入模块



我正试图将base导入到项目中,但遇到了一个错误。

设置渐变

enableFeaturePreview('VERSION_CATALOGS')
dependencyResolutionManagement {
versionCatalogs {
libs {
// https://mvnrepository.com/artifact/org.springframework/spring-core
version('spring', '5.3.14')
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter
version('spring-boot', '2.6.2')
alias('spring-core').to('org.springframework', 'spring-core').versionRef('spring')
alias('spring-context').to('org.springframework', 'spring-context').versionRef('spring')

alias('spring-boot').to('org.springframework.boot', 'spring-boot-starter').versionRef('spring-boot')
bundle('base', ['spring-core', 'spring-context'])
}
}
}

模块的构建.gradle

dependencies {
implementation(libs.base)
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

刷新渐变将产生以下错误

无法为org.gradle.accessors.dm.LibrariesForLibs.类型的扩展"libs"获取未知属性"base">

如何正确导入libs.base

从版本目录中引用捆绑包的正确方法是

libs.bundles.base

类似的插件使用:

libs.plugins.yourplugin

也可以参考版本,但工作方式略有不同。例如:

implementation group: "org.springframework.boot", name: "spring-boot-starter-web-services", version: libs.versions.spring.boot.get()

这假设您的目录中有一个版本定义,看起来像:

version('spring-boot', '2.6.7')

请注意,捆绑包、版本和插件都拼写为复数。

另请注意,从Gradle 7版本起,目录不再是功能预览。默认情况下,它们是可用的。此外,库的表示法也略有变化。您必须使用library而不是alias

有关更多信息,请参阅Gradle的支持网站。

最新更新