如何在父文件夹上的multimodule gradle项目中声明公共依赖项

时间:2018-04-30 18:23:39

标签: gradle

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

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

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

任何想法我该怎么做。

1 个答案:

答案 0 :(得分: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进行深入研究。