Search code examples
gradlemulti-project

Gradle embedded Project


Is it possible to embed multiple projects in a single build.gradle? Something along the lines of:

project projX {
    task a << {
    }
}

project projY {
    task a << {
    }
}

Both within the same build.gradle. Is this possible?

I am asking this because I have multiple projects with equivalent task names which I want to execute from the root project, e.g.

gradle a

However the projects contain only automation tasks, which require no source files or resource files at all. Creating subdirectories just for the build.gradle files to be stored seems very ugly to me. I could live with a solution with different .gradle files for each project, such as: build.gradle (root) projA.gradle, projB.gradle within the same directory, however embedding project objects in the root build.gradle seems like the better option, if it is available.


Solution

  • project(":projX") { ... }
    
    project(":projY") { ... }
    

    Note that you still need a settings.gradle.

    PS: It's not clear to me why you would want multiple projects in your case.