This message was deleted.
# community-support
s
This message was deleted.
v
I think it is if you really want to do that.
👍 1
e
you want a single command to build all the modules in a multimodule project?
t
Use case would be when I switch branch and want to rebuild the whole project with no apparent dependency (a service that call another through an http call), I don’t want to figure out what I should rebuild ; and let Gradle rebuild every build that changed. What would you consider for this? Endre yes, I would like one single command to build a composite project
n
Isn’t that the default behaviour if you simply call
./gradlew build
?
e
how about a script in
settings.gradle.kts
which crawls for all the potential sub-projects (any folder with a
build.gradle.kts
file inside), and for them, apply this:
Copy code
matchingFiles.forEach {
    val relativePath = it.relativeTo(rootDir)
        val projectName = ":${rootProject.name}-${relativePath.path.replace('/', '-')}"
        include(projectName)
        project(projectName).projectDir = it
}
t
Not in case of a composite build @Niels Doucet, task build doesn’t exist at root.
👍 1
e
this is what I use instead of manually adding all the modules manually
v
Isn’t that the default behaviour if you simply call
./gradlew build
?
Yes and no. It invokes all
build
tasks of the main project. Included builds are only built if used and only the parts that are used I think. So for example only their jars are built, but no tests run and so on.
👍 1
this is what I use instead of manually adding all the modules manually
Well, that has nothing to do with his question. And would also not consider sub-builds found instead of sub-projects found if that could be the case which it is in this case
Not in case of a composite build @Niels Doucet, task build doesn’t exist at root.
The question is why not? What does your main build do if it does not have a
build
task? Virtually any usual Gradle project has it.
Beware, I ask for the main "build", not "project"
t
@Endre Deak what I did is: build.gradle.kts
Copy code
tasks.register("build") { dependsOn(gradle.includedBuilds.map { it.task(":build") }) }
thing is you need all your includedBuilds to have a build task, which is not necessarily the case
One thing I do not understand is: Given a composite build, with an includedBuild api, which is a gradle multi-project
./gradlew :api:tasks
says that a build task exists (build - Assembles and tests this project.)
./gradlew :api:build
says that task doesn’t exist (Task ‘build’ is ambiguous in project ‘:api’. Candidates are: ‘buildEnvironment’, ‘buildScanPublishPrevious’.)
Is that some kind of bug? Or is there something I missed?
v
Check
./gradlew :api:tasks --all
. I guess there is
build
in some subproject. And if you do
tasks
it also shows the tasks that would match by pattern (
./gradlew build
executes
build
in all projects of a multi-project build where it is found). But I guess you will then not find a task
build
in the actual root project. This is indeed misleading if it is the case and should maybe display differently when called on an included build. If my assumption is correct I'd recommend you open an issue about it.
t
Ok, your assumption is indeed correct 👍 I’ll fill an issue tonight ; thank you for all your answers!
👌 1