3

I have the following multi-module project structure.

Root project 'reports-be'
+--- Project ':auth'
+--- Project ':builder'
|    +--- Project ':builder:base'
|    \--- Project ':builder:reporting'
\--- Project ':common'

When I run build task for /builder subproject and I expect that build task will be executed for all subprojects (for :builder:base and :builder:reporting).

gradle clean :builder:build

But gradle execute build task only for subproject :builder. According Gradle documentation build task should be completed for all subprojects.

Why doesn't it happen?

P.S. I found that the command gradle -p builder clean build works as I expected. But I really don't understand what is wrong with first mentioned gradle task.

P.S.S. I have build.gradle in every subproject and my settings.gradle looks like

rootProject.name = 'reports-be'
include 'common'
include 'builder'
include 'auth'
include 'builder:base'
include 'builder:reporting'
Vladimir
  • 525
  • 5
  • 15

2 Answers2

3

:builder:build is a qualified task name of the task build in the project :builder, so only this one task (and its dependencies) will be executed. The execution in all (sub-)projects is only possible for unqualified task names as build. You may switch to the builder directory and run gradle build from there, however this approach won't work if you want to run clean for all projects in the same invocation and it's kind of ugly when using the wrapper (gradlew). As far as I know, there is no direct solution for your use case.

If I get you right, the :builder project is just a dummy project for organization purposes and does not contain any actual sources or anything else to build. In this case, you may solve your problems using task dependencies inside builder/build.gradle:

task build {
    dependsOn ':builder:base:build', ':builder:reporting:build'
}
Lukas Körfer
  • 13,515
  • 7
  • 46
  • 62
  • Thank you for explanation. It is what I expect to know! Put my 2 cents to your explanation. For Gradle 6.3 correct command: ```build { dependsOn ':builder:base:build', ':builder:reporting:build' }``` – Vladimir May 21 '20 at 09:07
  • Also It works to switch directory and run ```gradle clean build``` (not `gradlew`) – Vladimir May 21 '20 at 09:10
  • Yes, but only if `gradle` is installed on the machine. If using the wrapper, this is often not provided. – Lukas Körfer May 21 '20 at 09:11
  • And you can only refer to the task `build` without creating it (like in your example), if it already exists, probably because you applied the `java` plugin. – Lukas Körfer May 21 '20 at 09:14
  • Thank you one more time. You are absolutly right, I have installed `gradle` on my machine and applied `java` plugin to my project :) – Vladimir May 21 '20 at 09:23
1

Three possible solutions which I found:

1. gradle -p builder clean build

2:

cd ./builder
gradle clean build

3. Add modification for builder/build.gradle (work for Gradle 6.3):

build {
    dependsOn ':builder:base:build', ':builder:reporting:build'
}

And run gradle clean build from root project directory. Thank you for this solution Lukas Korfer answer

Vladimir
  • 525
  • 5
  • 15