use*_*939 5 java dependencies gradle gradle-plugin
我正在尝试用java开发一个等级插件来配置版本目录。该插件可以通过两种方式之一配置版本目录。
libs.versions.toml依赖项目gradle文件夹中。libs.versions.toml文件作为插件源的一部分提供。toml我定义的文件。
[versions]
groovy = "3.0.5"
checkstyle = "8.37"
[libraries]
groovy-core = { module = "org.codehaus.groovy:groovy", version.ref = "groovy" }
groovy-json = { module = "org.codehaus.groovy:groovy-json", version.ref = "groovy" }
groovy-nio = { module = "org.codehaus.groovy:groovy-nio", version.ref = "groovy" }
commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = { strictly = "[3.8, 4.0[", prefer="3.9" } }
[bundles]
groovy = ["groovy-core", "groovy-json", "groovy-nio"]
[plugins]
jmh = { id = "me.champeau.jmh", version = "0.6.5" }
Run Code Online (Sandbox Code Playgroud)
插入
public class SettingsSupportPlugin implements Plugin<Settings> {
@Override
public void apply(@Nonnull Settings settings) {
configureDependencyResolution(settings);
}
private void configureDependencyResolution(Settings settings) {
copyFileFromJar("libs.versions.toml", "build/libs.versions.toml");
settings.getGradle().rootProject((rootProject) -> {
FileCollection tomlFile = rootProject.files("build/libs.versions.toml");
settings.dependencyResolutionManagement(
dependencyResolutionManagement -> dependencyResolutionManagement.versionCatalogs(
versionCatalogContainer -> versionCatalogContainer.register("libs",
versionCatalogBuilder -> versionCatalogBuilder.from(tomlFile))));
});
}
}
Run Code Online (Sandbox Code Playgroud)
发布插件后,并将其应用到依赖的项目settings.gradle文件中。当我尝试使用访问依赖项之一时implementation libs.groovy.core 遇到了问题
> Could not get unknown property 'libs' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Run Code Online (Sandbox Code Playgroud)
我最初的猜测是libs版本目录未创建。因此,我libs.versions.toml在依赖项目的目录中添加了一个文件gradle,并应用了上述插件(选项 1+ 2)。这给了我一个错误
Cannot add a VersionCatalogBuilder with name 'libs' as a VersionCatalogBuilder with that name already exists.
Run Code Online (Sandbox Code Playgroud)
这表明该version catalog名称libs是由创建的plugin,但不知何故我无法在我的依赖项目中引用它。我不确定我在这里做错了什么。
有什么想法吗?
| 归档时间: |
|
| 查看次数: |
1507 次 |
| 最近记录: |