Created
January 5, 2026 05:18
-
-
Save robinvanyang/f31563f3de6785ae997661814cbeddb7 to your computer and use it in GitHub Desktop.
gradle本地复合构建(跨工程引用module)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // add to settings.gradle.kts | |
| if (file("../Argos").exists()) { | |
| includeBuild("../Argos") { | |
| dependencySubstitution { | |
| substitute(module("redroid.log.argos:argos")) | |
| .using(project(":argos")) | |
| } | |
| } | |
| println("DEBUG: 已启用 Argos 的本地复合构建 (Composite Build)") | |
| } else { | |
| println("DEBUG: 未找到 Argos 本地路径,将使用 Maven 远程依赖") | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
注:from aistudio playground.
Composite Builds 的优势
真·实时修改:修改 LibraryA 的代码后,直接点击 MyApp 的 "Run",改动立即生效,不需要运行任何发布脚本(不需要 publishToMavenLocal)。
断点调试:你可以直接从 App 的代码跳进 LibraryA 的源码里打断点,就像它们是在同一个项目里一样。
重构利器:如果你在 App 里对 LibraryA 的类进行重命名(Refactor -> Rename),IDE 会自动跨项目修改 LibraryA 的源码。
无侵入性:不需要像 Git Submodule 那样学习复杂的 Git 命令,也不需要像直接复制源码那样破坏项目结构。
注意事项
Gradle 版本:建议两个项目的 Gradle 版本尽量接近,避免插件兼容性问题。
模块名称:substitute ... using project(':library-module') 这里的名字必须匹配 LibraryA 内部 settings.gradle 定义的名字。
同步构建:每次修改 settings.gradle 后,记得点击 IDE 的 "Sync Project with Gradle Files"。