Why sometimes gradle run jar task but doesn't run build task for every subproject

Why sometimes gradle run jar task but doesn’t run build task for every subproject when I run a customized task from root project. If I run gradle build it will execute entire build task for all subprojects, otherwise, it execute jar for some subprojects and execute build for others. Thanks.

Running the ‘build’ task for a project will in turn run ‘build’ for all its subprojects, as you have correctly described. However, if a build a particular subproject, only that subproject and its dependencies are built. In your case I assume there are project dependencies between your projects. If project ‘A’ depends on project ‘B’ (which is a Java project), the calling ‘:a:build’ will only require calling ‘:b:jar’ because that is all ‘A’ requires.