Modules

Specify all modules or subprojects in the top level settings.gradle.

// settings.gradle.kts
rootProject.name = "myproject"
include("module1")
include("module2")
include("module3")

Every module may have own build.gradle file. For example, you can specify dependency of that module.

dependencies {
    api(project(":module2"))
    api("org.jsoup:jsoup:1.13.1")
}

allprojects and subprojects blocks

You can specify common options in the top level build.gradle in the allprojects block for the root project and its subprojects.

You can specify common options in the top level build.gradle in the subprojects block for all subprojects.

Code example (Kotlin DSL)

merge subprojects in single .jar

Let's say you have modules in your library that you want to expose to users separately. And also the ability to use the library as one .jar file with all modules.

In this case root project don't have any code and the jar task will produce empty file.

To resolve this problem you can override the jar task like below in the root build.gradle.

tasks {

    jar {
        subprojects.forEach {
            dependsOn(":${it.name}:jar")
        }
        
        subprojects.forEach { subproject ->
            from({
                subproject.configurations.archives.allArtifacts.files.map {
                    zipTree(it)
                }
            })
        }
    }
}

As variant you can create new empty module, for example all. And add to its build.gradle following code

Code example
tasks {
   jar {
        val modules = setOf("module1", "module2", "module3")

        rootProject.subprojects.filter { it.name in modules }.forEach {
            dependsOn(":${it.name}:jar")
        }

        rootProject.subprojects
            .filter { it.name in modules /*it.name != "all"*/ }
            .forEach { project ->
                from({
                    project.configurations.archives
                        .allArtifacts.files.map {
                        zipTree(it)
                    }
                })
        }
    }
}