diff --git a/content/posts/2024/version-catalog-plugin-wordaround/index.en.md b/content/posts/2024/version-catalog-plugin-wordaround/index.en.md index 4ff7fcb..d96ba43 100644 --- a/content/posts/2024/version-catalog-plugin-wordaround/index.en.md +++ b/content/posts/2024/version-catalog-plugin-wordaround/index.en.md @@ -3,7 +3,7 @@ title: "A beautiful workaround for accessing Gradle Version Catalogs from Precom # slug: "" # if :slug is in the permalinks configuration, use this to resolve URL conflict with other posts date: 2024-05-12T14:52:55Z # if year month day in the permalinks configuration and other posts have the same date, modify this to resolve URL conflict with other posts lastmod: 2024-05-12T14:52:55Z # no longer needed if enableGitInfo = true -draft: true # remember to change it back to false before opening the PR for publishing +draft: false # remember to change it back to false before opening the PR for publishing authors: [CXwudi] # no quotes featuredImage: "img/featured image.webp" description: "Using the gradle-buildconfig-plugin or the BuildKonfig plugin to access Gradle Version Catalogs from precompiled script plugins" @@ -163,7 +163,7 @@ Several intelligent people have proposed great workarounds to this issue. The mo Are there other workarounds, preferably without hacks? -Fortunately, there is one for the `plugins {}` block mentioned by [this comment](https://github.com/gradle/gradle/issues/15383#issuecomment-1855984127). Since applying external plugins to the precompiled script plugin requires adding the corresponding dependency of the external plugin to the `build.gradle.kts` file, you can apply the version catalog to that dependency. This method assumes that the `settings.gradle.kts` file in the build project [imports the same version catalog](https://docs.gradle.org/current/userguide/platforms.html#sec:importing-catalog-from-file) used in the main project. I also discovered that the method works for setting plugins, as I described in [this forum post](https://discuss.gradle.org/t/how-to-use-version-catalog-in-the-root-settings-gradle-kts-file/44603/5). +Fortunately, there is one for the `plugins {}` block mentioned by [this comment](https://github.com/gradle/gradle/issues/15383#issuecomment-1855984127). Since applying external plugins to the precompiled script plugin requires adding the corresponding dependency of the external plugin to the `build.gradle.kts` file, you can add that dependency to the version catalog. This method assumes that the `settings.gradle.kts` file in the build project [imports the same version catalog](https://docs.gradle.org/current/userguide/platforms.html#sec:importing-catalog-from-file) used in the main project. I also discovered that the method works for setting plugins, as I described in [this forum post](https://discuss.gradle.org/t/how-to-use-version-catalog-in-the-root-settings-gradle-kts-file/44603/5). @@ -274,6 +274,6 @@ dependencies { ## Conclusion -The method that utilizes the gradle-buildconfig-plugin or the BuildKonfig plugin is a beautiful workaround for accessing Gradle Version Catalogs from precompiled script plugins. It is not too hacky, guaranteed to work in any Gradle project, and doesn't have the limitation where it is only accessible from the `plugins {}` block or the `dependencies {}` block. It is a great solution for centralizing version management in your Gradle project. +The method, that utilizes the gradle-buildconfig-plugin or the BuildKonfig plugin for accessing Gradle Version Catalogs from precompiled script plugins, is a beautiful workaround. It is not too hacky, guaranteed to work in any Gradle project, and doesn't have the limitation where it is only accessible from the `plugins {}` block or the `dependencies {}` block. It is a great solution for centralizing version management in your Gradle project. I hope this workaround can help you in your Gradle project. If you have any questions or suggestions, feel free to leave a comment below. 😊 diff --git a/content/posts/2024/version-catalog-plugin-wordaround/index.zh-cn.md b/content/posts/2024/version-catalog-plugin-wordaround/index.zh-cn.md index 7c20f58..4dd1c33 100644 --- a/content/posts/2024/version-catalog-plugin-wordaround/index.zh-cn.md +++ b/content/posts/2024/version-catalog-plugin-wordaround/index.zh-cn.md @@ -1,35 +1,39 @@ --- -title: "Gradle Version Catalog Issue" -slug: "gradle-version-catalog-issue" # if :slug is in the permalinks configuration, use this to resolve URL conflict with other posts -date: 2024-05-12T14:53:10Z # if year month day in the permalinks configuration and other posts have the same date, modify this to resolve URL conflict with other posts -lastmod: 2024-05-12T14:53:10Z # no longer needed if enableGitInfo = true -draft: true # remember to change it back to false before opening the PR for publishing -authors: [] # no quotes -featuredImage: "" -description: "" +title: "从预编译脚本插件访问Gradle版本目录的漂亮解决方案" +# slug: "" # 如果在永久链接配置中有:slug,使用这个来解决与其他帖子的URL冲突 +date: 2024-05-12T14:52:55Z # 如果永久链接配置中有年月日,并且其他帖子有相同的日期,修改这个来解决URL冲突 +lastmod: 2024-05-12T14:52:55Z # 如果启用了enableGitInfo,则不再需要 +draft: false # 发布前记得将其改为false +authors: [CXwudi] # 没有引号 +featuredImage: "img/featured image.webp" +description: "使用gradle-buildconfig-plugin或BuildKonfig插件从预编译脚本插件访问Gradle版本目录" # license: 'CC BY 4.0' -# need quotes for all three -tags: [] -categories: [] +# 所有三个都需要引号 +tags: [devops] +categories: [tech] series: [] series_weight: -# you can copy any config from [params.page] to here to override global default +# 你可以从[params.page]复制任何配置到这里来覆盖全局默认 -# outdatedArticleReminder: # uncomment to enable, default is false in config +# outdatedArticleReminder: # 取消注释以启用,默认在配置中为false # enable: true # reminder: 180 # warning: 365 -# sponsor: # uncomment to disable, default is false in config - # enable: false -# table: # uncomment to disable, default is true +sponsor: + enable: true + bio: "写完这篇文章后,我感到非常疲惫 😫。我需要一杯咖啡 ☕ 来提神。如果你喜欢我的Gradle 🐘 解决方案,你介意请我喝一杯咖啡吗?感谢你的支持!🤗" + custom: "
" +# table: # 取消注释以禁用,默认为true # sort: false -# comment: # uncomment to disable comment system +# comment: # 取消注释以禁用评论系统 # enable = false -# lightgallery: true # uncomment if using the better image shortcode +lightgallery: true # 如果使用更好的图片shortcode则取消注释 +code: + maxShownLines: 50 seo: - images: [] # same as featuredImage + images: ["img/featured image.webp"] # 与featuredImage相同 --- 太长不看:在 `buildSrc/build.gradle.kts` 中应用 [gradle-buildconfig-plugin](https://github.com/gmazzo/gradle-buildconfig-plugin) 或 [BuildKonfig](https://github.com/yshrsmz/BuildKonfig) 插件。 @@ -39,7 +43,7 @@ seo: **来源**: [Medium](https://medium.com/@gopalsays108/android-gradle-version-catalog-by-gopal-cf459e90fb92) {{< /admonition >}} {{< admonition type=info title="注意" open=true >}} -此文章是从本站英文版原文通过[什么工具]翻译并适当修改而来,可能会出现语言不自然等Bug,请予以谅解。 +此文章是从本站英文版原文通过GPT-4 Turbo翻译并适当修改而来,可能会出现语言不自然等Bug,请予以谅解。 {{< /admonition >}} ## 简介 @@ -129,3 +133,150 @@ Gradle官方文档推荐两种[构建多模块项目的结构](https://docs.grad 它看起来就像一个普通的Gradle项目,对吧? 所以,接下来就是precompiled script plugin的真相了。 + +### precompiled script plugin的真相 + +你是否曾经好奇为什么precompiled script plugin会被放在`src/main/kotlin`文件夹中?🤔 就像上面的`shared-build-conventions.gradle.kts`示例。它能否就留在构建项目的第一层,比如`build-logic/shared-build-conventions.gradle.kts`? + +这里,我想邀请你观看{{