Im trying to include external Gradle project into my own and it seems like I don’t understand some fundamental things here. Here is what my project structure looks like:
ProjectA
|-- build.gradle
|-- settings.gradle
|-- app
|-- build.gradle
|-- src
ProjectB
|-- build.gradle
|-- settings.gradle
|-- lib
|-- build.gradle
|-- src
What Im trying to do - is to include ProjectB/lib
into my ProjectA
.
The way I’m doing that is as follows:
ProjectA/settings.gradle
:
include ':coolLib'
project(':coolLib').projectDir = new File('../ProjectB/lib')
Now I can refer to project B as a dependency:
ProjectA/app/build.gradle
:
compile project(':coolLib')
The problem is that ProjectB/lib/build.gradle
has some assumptions about root project - i.e has references to extra properties from ProjectB/build.gradle
( i.e. rootProject.ext.someFancyVariable
).
But as I understand, when I build ProjectB/lib
as part of ProjectA
, rootProject points to ProjectA
rather ProjectB
, so this someFancyVariable
is not available.
I realize that I could just reconfigure ProjectB
gradle configuration or add relevant extra variables to ProjectA
, but I don’t really like any of these approaches because:
- I don’t want to modify
ProjectB
since this is a third party lib and I want to keep it untouched - I don’t want to modify my
ProjectA
just to makeProjectB
happy because extra variable - is just a tip of the iceberg.ProjectB/lib
also uses custom gradle plugins which are located inProjectB
root directory (apply from: "$rootDir/gradle/somePlugin.gradle
)
Is there any easy solution to build ProjectB/lib
as part of ProjectA
in my situation?
P.S. Sorry for confusing post title - originally it was “Multiproject build”, but this title is already taken So I had to come with some other weird name. Naming was never my strongest side…