Subproject without build.gradle file

In my root project I have some common dependencies and settings configured for all subprojects. One subproject has no additional dependencies or configuration and is therefore without a build.gradle file. This causes an error in a plugin I’m using (File ‘/[filesystem path]/build.gradle’ specified for property ‘inputFile’ does not exist).

When I raised this issue with the maintainer of the plugin he questioned the validity of not having a build.gradle file for all subprojects.

So, I’m wondering, is it regarded as a bad practice to skip the build.gradle file if not needed or is it a supported (and perhaps documented) feature in Gradle?

Gradle gives you the freedom to do everything in the root project’s build.gradle if you wish.

For simple projects that’s just fine. As your modules within a multi-module build get more hairy, it’s common to separate into a build.gradle per module. But it’s definitely not enforced by gradle

Horses for courses :smile:

1 Like

Hello,

For our case, we use common dependencies definition in the root project and a build.gradle with specifics in each sub modules and it’s work fine. :slight_smile:

Hello, sorry for reviving this seemingly resolved old topic, but is there documentation on the Gradle behavior, when a directory D with no build script, wraps some Gradle sub-projects, an intermediate project :D is created?

Sorry if this sounds too simple but I couldn’t find the documentation about it, thanks.

Yes, you are right.
If you do include(':D:foo') then you are effectively creating two projects, D and its subproject foo.
If you don’t want that, you can do include(':foo') and then configure its project directory to be d/foo.

Other than that, configuring subprojects from the root project should not be done anyway for various reasons. Instead you should write convention plugins that you then apply to the projects directly where those conventions should be effective: Sharing Build Logic between Subprojects.

1 Like