I have 2 Gradle projects both inside the same directory. The directory structure is as follows:
ParentDirectory\
GradleProjectA\
build.gradle
GradleProjectB\
settings.gradle
build.gradle
I want to add GradleProjectA
as a dependency to GradleProjectB
. In the settings.gradle
for GradleProjectB
, I've tried adding include 'GradleProjectA'
and then in build.gradle
: compile project(':GradleProjectA')
but that didn't work.
Any help would be greatly appreciated. Thanks.
The way I did something like this is as follows:
GradleProjectB/settings.gradle
:
include ':GradleProjectA'
project(':GradleProjectA').projectDir = new File('../GradleProjectA')
GradleProjectB/build.gradle
:
compile project(":GradleProjectA")
In the latest version of Gradle, you can use Composite Builds, like that:
In GradleProjectB's settings.gradle, add the following line:
includeBuild "../GradleProjectA"
It will automatically handle dependency collisions and all that stuff.
The settings.gradle file needs to be in the parent directory specifying both.
Try the following format:
ParentDirectory\
build.gradle
settings.gradle <-- include 'GradleProjectA', 'GradleProjectB'
GradleProjectA/
build.gradle
GradleProjectB/
build.gradle
Edit:
Ok if your Parent Directory is not a build directory then you can do the following:
in your gradle project b settings.gradle file try the following:
includeFlat("GradleProjectA") // Include the project
in your b build.gradle:
compile project(":GradleProjectA")
includeFlat reference
If GradleProjectA
and GradleProjectB
are part of one multi-project Gradle build, then you probably want the settings.gradle
in ParentDirectory
and there include A and B. The way you use settings.gradle
is not correct. Maybe you should re-read the section about multi-project gradle builds in the User Guide.
If the two projects are indiviual projects but you still want to depend on A from B, you might prefer to build A, release it to some repository (possibly the mavenLocal repository) and then depend on the built artifacts from project B.
The following should do the trick:
root
+-- projectA
| +-- build.gradle
| => dependencies { compile project(':common') }
| +-- settings.gradle
| => include ':common'
| project(':common').projectDir = new File('../common')
+-- projectB
| => same as projectA
+-- common
+-- build.gradle
=> regular build, probably with a "jar" section