Is there a Workspace Dir concept in Gradle?

In a multi-project build, normally settings.gradle sits in the top dir and source sits in sub dirs…
The project.rootDir method would return repo and the project sources would sit under subproject1 and subproject2

Using the includeFlat way of defining projects changes this. For example…
Here the project.rootDir returns repo/master. So subprojects no longer sit below project.rootDir.

Is there a method/setting that would return the repo dir for both the above setups? This is what I’d refer to as the workspace dir as it is the parent dir to all source and build files.

You could add your own property to all the projects. Something like the following in master/build.gradle (untested):

allprojects {
    ext.workspaceDir = project.rootDir.parentFile

Projects can then reference it via project.workspaceDir, or simply workspaceDir.

Thanks Chris

That makes sense but I guess I was hoping for something built-in across all types of Gradle projects (single, hierarchical, flat).

Do you happen to know whether the use of includeFlat is encouraged these days? I couldn’t find any example projects on the Gradle github site so wondered if people were moving away from it.

I don’t believe any particular directory structure is encouraged or discouraged. If using includeFlat works for your builds then I see no problem with using it.

I do think that the first layout is probably more common. It is also what I use, as a matter of personal preference and professional convention.

Afaik there is no such thing as a workspace directory.
It would also be very hard to define, because those two layouts are just the two conventional ones supported out of the box.
But after using include or includeFlat, you can actually set the project directory of that project to any arbitrary value.