【问题标题】:How to declare common dependencies in multimodule gradle project on parent folder如何在父文件夹的多模块 gradle 项目中声明公共依赖项
【发布时间】:2018-10-10 21:07:41
【问题描述】:

我有多模块 gradle 项目。假设项目parent 有模块module1module2

我也将settings.gradle 中的两个模块都包含在了父项目中。

当我在父项目的build.gradle 中声明公共依赖项时,两个项目都没有编译,但是当我在每个模块的build.gradle 中添加依赖项时,模块编译成功。

任何想法我该怎么做。

【问题讨论】:

    标签: gradle


    【解决方案1】:

    您可以使用父模块中的 allprojects 语句声明项目中所有模块的依赖关系。这是在您的父 build.gradle 文件中这样做的基本方法:

    allprojects {
        // Plugins can go here, example:
        apply plugin: 'java'
    
        dependencies {
            // Dependencies go here, example:
            compile group: 'org.apache.shiro', name: 'shiro-core', version: '1.4.0'
        }
    }
    

    查看thisthis 答案以更深入地了解多项目的配置点。
    还可以查看 Gradle documentation 关于此主题的深入了解。

    【讨论】:

    • 我还要注意,在处理多模块项目时,您在 settlings.gradle 中使用该项目的所有名称,例如`rootProject.name = 'TEST_PROJECT' 包括'ModuleOne' 包括'ModuleTwo' `
    猜你喜欢
    • 2012-03-21
    • 2019-12-19
    • 1970-01-01
    • 2019-07-08
    • 2023-02-24
    • 2014-01-19
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    相关资源
    最近更新 更多