user51
user51

Reputation: 10143

How to declare common dependencies in multimodule gradle project on parent folder

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

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

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.

Any Idea how can I do this.

Upvotes: 10

Views: 11064

Answers (1)

UnlikePluto
UnlikePluto

Reputation: 3369

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

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.

Upvotes: 12

Related Questions