Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gradle

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.

like image 529
Rajkumar Natarajan Avatar asked Apr 30 '18 18:04

Rajkumar Natarajan


People also ask

Where should I add dependencies in Gradle project?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.


1 Answers

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.

like image 159
UnlikePluto Avatar answered Oct 10 '22 04:10

UnlikePluto