jAckOdE
jAckOdE

Reputation: 2500

Gradle dependencies not found in mutil project setup?

I have a project setup like this

+ rootProject
    + module1
       + src
         build.gradle
    + module2
       + src
         build.gradle
    + src
      build.gradle
      settings.gradle

Content of rootProject/build.gradle

evaluationDependsOn(':module1')

apply plugin: 'java'

dependencies {
  compile project(':module1')
  compile project(':module2')
}


task myTask (type: JavaExec) {
    main = 'org.gradle.example.Test.Main'
    classpath runtimeClasspath
  }

Content of module1/build.gradle

apply plugin: 'java'

repositories { 
  mavenCentral() 
}

dependencies { 
  compile 'commons-codec:commons-codec:1.9' 
}

Content of module2/build.gradle

apply plugin: 'java'

The dependencies graph

root --> module1 --> commons-codec
     --> module2

gradle report this at build with command gradle build in root folder

Could not resolve all dependencies for configuration ':compile'.
> Could not find commons-codec:commons-codec:1.9. Required by:
      :rootProject:unspecified > rootProject:codec:unspecified

if I add dependencies block in the rootProject's build file the it get build normally. As you see, i already determine the dependencies in module1 build file. Why gradle keep saying that it couldnt resolve?

Do i need to put all dependencies of submodule in root build files?

Upvotes: 1

Views: 3177

Answers (1)

Opal
Opal

Reputation: 84756

First of all I see that You're missing settings.gradle file which is necessary in multimodule projects. You need to create it at the same level as rootProject/build.gradle is located.

The content should be

include 'module1', 'module2'

UPDATE

Ok, to root build.gradle added following piece of code:

allprojects {
    repositories {
        mavenCentral()
    }
}

And removed from module1/build.gradle the repositories section. Now it works. Dependencies are fetched and displayed. Currently no idea what is the explanation.

Upvotes: 1

Related Questions