7

I've asked this and this questions a long time ago, and now that I have the time(don't have a choice) I've worked my way through the setting up of some of my projects.

The structure is similar to the one in the previous question but with a twist...

┌Just a folder
│
├── Project 1 - (Pure Java Modules)
│    │
│    ├── Module A1
│    ├── Module B1
│    :
│    └── Module Z1
│  
├── Project 2 - (Android Libraries Modules)
│    │
│    ├── Module A2
│    ├── Module B2
│    :
│    └── Module Z2
│  
└── Actual Android Project

That all the sub modules depends on the previous one e.g. Z1 depends on X1 ... B1 depends on A1 same goes for the {X}2 Series.

Since I have multiple projects which depends on the same top libraries(Z2,Z1), I would like to save me agony and text and avoid as much as possible duplicating the following across projects:

In the settings file:

include ':project1', ':project1:A1', ':project1:B1',..., ':project1:Z1'
include ':project2', ':project2:A2', ':project2:B2',..., ':project2:Z2'
project(':project1').projectDir = new File(settingsDir, '../somepath1/project1')
project(':project2').projectDir = new File(settingsDir, '../somepath2/project2')
project(':project2:A2').projectDir = new File(settingsDir, '../somepath2/project2/A2')
...
... etc...

In the build file:

evaluationDependsOn(':Project1')
evaluationDependsOn(':Project2')

dependencies {
    compile project(':Project1:A1')
    compile project(':Project1:B1')
    ...
    compile project(':Project1:Z1')

    compile project(':Project2:A2')
    compile project(':Project2:B2')
    ...
    compile project(':Project2:Z2')
}

It makes sense (assuming this is doable like in Eclipse/Maven/other dependencies) that if I'll add the top libraries projects Z1,Z2 to the application the rest of the nested dependencies within the hierarchy of sub projects would resolve without the need to literally specify each and every one on each of my top projects.

Is this possible with Gradle? How would I approach this with Gradle?

Community
  • 1
  • 1
TacB0sS
  • 10,106
  • 12
  • 75
  • 118
  • What you want isn't trivially possible because settings.gradle is where you specify all module includes, and you can only have one of them per project. It needs to specify all needed modules, and Gradle isn't able to know that Z1 depends on A1 without A1 being set up in settings.gradle. If this is really inconvenient for you, you could consider writing some custom code in settings.gradle (or write a plugin) to set up a number of dependencies. – Scott Barta Nov 10 '14 at 20:50
  • OK... So if this is not supported by Gradle, do you have any thought about how this sort of setup should be handled? would I have to duplicate my dependency projects in each of my top projects? – TacB0sS Nov 11 '14 at 07:27
  • 1
    If it isn't that much of a pain, just deal with it. If it is, then write some custom code to set up the dependencies and avoid boilerplate. You may find it useful to import Gradle script from a separate file; see http://stackoverflow.com/questions/2265283/how-can-i-import-one-gradle-script-into-another – Scott Barta Nov 11 '14 at 16:30
  • I'm just starting to modularize 3 Android apps into common libs, so it might be similar to your issues. Have you thought about using soft-links to "include" libraries as they would be subdirectories of your app project? (Or maybe you're one of the poor souls who have to work on Windows...) – hgoebl Aug 09 '15 at 18:54

0 Answers0