How include required gradle project into another project

Here I will tell you how to include the required gradle project into another project. Situation may occur when you need to have dependency of another gradle project into your current gradle project, but neither of these projects is a multi-module project. So in this case you can easily add the required project into your current working project.

To include another gradle project you need to edit the settings.gradle file of the current project. In the current project’s settings.gradle file, you have to add the project’s name which you want to include in the current project. The name of the project can be found in the settings.gradle file by visiting the key/value pair = '<project name>'.

Let’s say your current project name is spring-boot-rest-crud and it is found under current project’s settings.gradle file as = 'spring-boot-rest-crud'.

Let’s say you have another project and the name found in settings.gradle file is = 'spring-boot-rest-test'.

For the understanding of this example I assume it is a Junit test project which is going to test the REST controller APIs written into spring-boot-rest-crud. Ideally Junit test cases are written into the same project under test resources.

Now let’s say you want to include the project spring-boot-rest-crud into spring-boot-rest-test.

So edit the file settings.gradle under project spring-boot-rest-test and add the following lines into it after = 'spring-boot-rest-test'.

include ":spring-boot-rest-crud"
project(":spring-boot-rest-crud").projectDir = file("../spring-boot-rest-crud")

In the above, in first line I have included the project. In the next line I have added the project’s root directory. For my example, the current project spring-boot-rest-test and the other project spring-boot-rest-crud are in the same directory. If you have those projects into different directory then you have to configure project directory accordingly.

You also have to include the project as a dependency in your build.gradle script under dependencies {...} section.

implementation project(":spring-boot-rest-crud")

That’s all about how to include required project into another gradle project without creating multi-module projects.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *