How to define dependencies across project?


(uyentvu) #1

All,

I have the following code structure: ‘root-projectA’ and ‘root-projectB’. They are 2 separate projects. ‘root-projectB’ has a lib directory that contains all the jar files that subprojects in ‘root-projectA’ need/depend on at compile time.

root-projectA —build.gradle —settings.gradle

—subproject1/

—subproject2/

root-projectB —lib/ (contain jar files)

How can I define the dependencies in root-projectA’s build.gradle, so that it can find all the jar files in root-projectB/lib to compile its subprojects successfully? I tried the following but it did not work.

root-projectA’s build.gradle: repositories {

flatDir name: ‘libRepository’, dirs: [’…/root-projectB/lib’]

}

dependencies {

compile fileTree(dir:’…/root-projectB/lib’, include:’*.jar’)

}

Thanks in advance.


(Peter Niederwieser) #2

With a ‘flatDir’ repository, you’ll still have to list the dependencies one-by-one. Hence your ‘fileTree’ try is probably the better choice (it’s an alternative to the ‘flatDir’ approach). However, it looks like you declared the dependencies for the root project instead of the subprojects. Try this:

subprojects {
  dependencies {
     compile fileTree(dir:'../../root-projectB/lib', include:'*.jar')
   }
}

(uyentvu) #3

Peter,

Thanks so much for your response. It worked.

Regards,