Gradle multimodules. If gradle.build file is changed for sub modules. No tasks are available

Hello

I am working with Gradle 3.5 and I have the following situation.

I work with Spring Framework through multi modules. Consider the following structure:

  • root
    build.gradle
  • child-01
    build.gradle
  • child-02
    build.gradle
  • child-03
    build.gradle

Until here all is Ok.

From above observe each .gradle file has the same name. It is build

Through the gradle tasks command is possible list in the console all my own tasks for each build.gradle file from each sub module. Furthermore, if the gradle project command is used I can see each project listed with its respective description.

Working with Jenkins all works fine where I am able to call any task from any build.gradle file from each sub module

I did the following variation:

  • root
    build.gradle
  • child-01
    child-01.gradle
  • child-02
    child-02.gradle
  • child-03
    child-03.gradle

For each submodule each build.gradle file has been renamed to child-0#.gradle respectively

Now the gradle tasks command does not print my own tasks and Jenkins fails because the tasks are not available. The gradle project command prints all the sub modules but without the description.

What is the solution?

By default, Gradle only looks for the filename “build.gradle”. You can change the filename in your settings.gradle file using ProjectDescriptor.setBuildFileName(String).

For example:

include( 'child-01' )
include( 'child-02' )
include( 'child-03' )

rootProject.children.each { child ->
    child.buildFileName = "${child.name}.gradle"
}