Uma Mageshwari
Uma Mageshwari

Reputation: 81

How to add Project Dependency using gradle?

I am facing the following problem. I need to build the multi-project, but when I try to add the dependency I got the following error.

Root Project's settings.gradle:

include 'DbServices','HelloWeb'

Root Project's build.gradle:

apply plugin: 'java'
project(':HelloWeb') {
   dependencies {
      compile (':DbServices')   
   }
}

DbServices's build.gradle:

apply plugin: 'java'

HelloWeb's build.gradle:

apply plugin: 'java'

However, then I am getting the following error when synchronize with the gradle tasks on Root Project:

Executing command: "tasks"

FAILURE: Build failed with an exception.

Upvotes: 6

Views: 17968

Answers (2)

Peter Niederwieser
Peter Niederwieser

Reputation: 123986

The notion of compile dependencies is introduced by the java plugin. Therefore, this plugin has to be applied (to the HelloWeb project) before declaring dependencies. The easiest way to fix this is to move the dependencies block into HelloWeb's build.gradle. Additionally, the project dependency syntax needs to be fixed according to JB Nizet's answer.

Upvotes: 2

JB Nizet
JB Nizet

Reputation: 692151

The documentation uses the following syntax:

dependencies {
    compile project(':DbServices')
}

Upvotes: 11

Related Questions