21 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. java gradle Share edited Apr 7, 2016 at 15:13 technophobia 2,61411 gold badge2020 silver badges2929 bronze badges asked Apr 7, 2016 at 14:22 Josh M 11.5k77 gold badges3838 silver badges4848 bronze badges Why didnt work? Which error do u get? – [Héctor](https://stackoverflow.com/users/3026283/h%c3%a9ctor) [Apr 7, 2016 at 14:28](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment60568523_36479097) ![[./resources/java-gradle-local-project-dependency-stack-overflo.resources/svg_2.svg]] It just doesn't recognize GradleProjectA as a valid dependency. – [Josh M](https://stackoverflow.com/users/1255746/josh-m) [Apr 7, 2016 at 14:29](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment60568573_36479097) Try replacing `include 'GradleProjectA'` for `include ':GradleProjectA'` – [Héctor](https://stackoverflow.com/users/3026283/h%c3%a9ctor) [Apr 7, 2016 at 14:31](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment60568637_36479097) Tried that, also did not work. – [Josh M](https://stackoverflow.com/users/1255746/josh-m) [Apr 7, 2016 at 14:47](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment60569451_36479097) Add a comment 6 Answers Sorted by: 23 ==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") Share answered Apr 7, 2016 at 17:12 Pavel Dudka 20.7k77 gold badges6969 silver badges8383 bronze badges 1 By the way, compile project(":GradleProjectA") needs to be to be inside the dependencies{....} section of the build.gradle of ProjectB – [William](https://stackoverflow.com/users/2178360/william) [Jul 17, 2019 at 19:03](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment100688116_36482966) 3 Sorry it gives me error: `> Project with path ':ProjA' could not be found in project ':ProjB'.` Any suggestions? Thanks! – [ch271828n](https://stackoverflow.com/users/4619958/ch271828n) [Sep 9, 2020 at 6:29](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment112829192_36482966) Add a comment 15 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. Share answered Aug 27, 2018 at 12:35 Cosmin Ioniță 3,39844 gold badges2323 silver badges4848 bronze badges 1 I want to use this trick on a project that is using a specific revision of another project that is waiting for a PR to be merged and so it hasn't been deployed yet (and so my project will have to wait for a while). I downloaded the _other_ project into my local and built it. Would this trick work in this case? – [eftshift0](https://stackoverflow.com/users/2437508/eftshift0) [Oct 19, 2018 at 14:52](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment92702352_52039513) Add a comment 3 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 Share edited Apr 7, 2016 at 17:09 answered Apr 7, 2016 at 14:39 bszeliga 1281111 bronze badges ParentDirectory isn't a Gradle project, it's just an empty IntelliJ project. – [Josh M](https://stackoverflow.com/users/1255746/josh-m) [Apr 7, 2016 at 14:42](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment60569187_36479494) Update answer to account for non-gradle parent directory. – [bszeliga](https://stackoverflow.com/users/2920722/bszeliga) [Apr 7, 2016 at 15:22](https://stackoverflow.com/questions/36479097/gradle-local-project-dependency#comment60571023_36479494) Add a comment 1 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 Share edited Mar 30, 2018 at 3:25 answered Mar 29, 2018 at 2:48 MonoThreaded 11.2k1111 gold badges6969 silver badges100100 bronze badges Add a comment 0 You can create a settings.gradle in the parent directory. This just associates GradleProjectA with GradleProjectB. This is the approach used in the official Gradle docs. It would look like the following: ParentDirectory/settings.gradle rootProject.name = 'RootProject' include 'GradleProjectA', 'GradleProjectB' Then in GradleProjectB/build.gradle, you can simply write implementation project(':GradleProjectA') under dependencies. Share answered Dec 11, 2022 at 21:06 thenewpotato 9199 bronze badges Add a comment -1 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. Share answered Apr 7, 2016 at 14:38 Vampire 33.8k33 gold badges7373 silver badges9999 bronze badges Add a comment Your Answer Sign up or log in ![[./resources/java-gradle-local-project-dependency-stack-overflo.resources/svg_9.svg]] Sign up using Google ![[./resources/java-gradle-local-project-dependency-stack-overflo.resources/svg_10.svg]] Sign up using Facebook ![[./resources/java-gradle-local-project-dependency-stack-overflo.resources/svg_11.svg]] Sign up using Email and Password Post as a guest Name Email Required, but never shown By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy Not the answer you’re looking for? Browse other questions tagged java gradle or ask your own question.