Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle multi project root-level build task

I've got a very basic multi-project Gradle setup like this:

root
+--- build.gradle
+--- settings.gradle
+--- subproject1
     \--- build.gradle
\--- subproject2 
     \--- build.gradle

The settings.gradle file includes both subprojects. The root project does not apply the java plugin, but both subprojects do. Everything builds as expected when using gradle build.

But, as far as i understand, since i don't apply the java plugin at the root project, it is not supposed to have a build task.

  • the output of gradle tasks, shows a build task.
  • but the output of gradle tasks --all shows only :subproject1:build and :subproject2:build listed instead.

So my question is - what exactly is executed in this scenario? Does gradle just find every task that matches the supplies pattern in all subprojects? Are there any specific rules about this task name resolution? Where can i find more info about this?

like image 572
Kassiar Avatar asked Sep 09 '26 16:09

Kassiar


1 Answers

Yes, you are right. If you do use just a task name or task name abbreviation, the task is executed in all subprojects of the current directory. If you want to only call subporject1s build task, either use the absolute path to it with gradle :subproject1:build or a relative path. If you are in the root directory e. g. the relative path would be gradle subproject1:build.
You can read more about it at https://docs.gradle.org/current/userguide/intro_multi_project_builds.html#N10762.

Btw. you should consider using the Gradle Wrapper. Each and every project jusing Gradle should also use the Gradle Wrapper. It is one of the most effective strengts of Gradle, as you need only Java installed, not Gradle or Maven or ant or anything else and the build always runs with the Gradle version you designed it to run with.

like image 57
Vampire Avatar answered Sep 12 '26 05:09

Vampire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!