I am transforming application from Ant to Gradle. The application consists of three smaller parts: frontend, backend and common. The whole codebase shares the same project directory. The directory structure is as follows:
root
|-- src
|
|-- frontend
|
|-- backend
|
|-- common
|-- frontend.gradle
|-- backend.gradle
|-- common.gradle
By setting the ‘includes’ and ‘excludes’ in ‘sourceSets.main.java’ in the specific *.gradle files correctly, I can build these three projects individually.
Now, I’d like to set up this scenario as a Gradle multi-project build without changing the directory structure to get the advantage of project dependencies.
To achieve this, I moved the project specific *.gradle files to a subfolder called ‘projects’. And I added a ‘settings.gradle’ and ‘build.gradle’ file to the root directory.
root
|-- src
|
|-- frontend
|
|-- backend
|
|-- common
|-- projects
|
|-- frontend.gradle
|
|-- backend.gradle
|
|-- common.gradle
|-- build.gradle
|-- settings.gradle
In the ‘settings.gradle’ file I manipulate the ProjectDescriptor so that the project’s directory is the root directory.
include 'common'
include 'frontend'
include 'backend'
ProjectDescriptor projectDescriptor = project(":common")
projectDescriptor.projectDir = rootDir
projectDescriptor.buildFileName = new File(rootDir, "projects/"+projectDescriptor.name+".gradle")
Unfortunately, this approach fails with the following exception:
Could not select the default project for this build. Multiple projects in this build have project directory ‘/home/my’: [root project ‘my’, project ‘:common’]
Is it even possible to have several projects sharing the same directory? Do I just have to avoid the exception? Or use a completely different approach?