本文介绍了如何在父文件夹的多模块Gradle项目中声明公共依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多模块gradle项目.假设项目 parent 具有模块 module1 module2 .

I've multi-module gradle project. Let's say project parent has modules module1 and module2.

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

I have included both the modules in settings.gradle in the parent project as well.

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

When I declare the common dependencies in build.gradle of parent project, both the project is not compiling but when I add the dependencies in build.gradle of each module then the modules are compiling successfully.

任何想法我该怎么做.

推荐答案

您可以使用父模块中的allprojects语句为项目中的所有模块声明依赖项.这是在父build.gradle文件中执行此操作的基本方法:

You can declare dependencies for all modules in your project using the allprojects statement in your parent module. This is the essential way of doing so in your parent build.gradle file:

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'
    }
}

检查答案,以更深入地了解多项目的配置点.
还可以查看有关该主题的Gradle 文档进行深入了解

Check this and this answer for more insight on the configuration point of a multi project.
Also have a look at the Gradle documentation about this topic for a deep dive.

这篇关于如何在父文件夹的多模块Gradle项目中声明公共依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:05