I have noticed that the two approaches in the title do not behave in the same way, for example the latter will run the specified task for all sub-projects where as the former will just run the task for the specified project only.
I would expect both to behave the same, since in both cases the same task is being executed, so I am wondering conceptually what is the difference in meaning between the two approaches given in the title?
The command ‘gradle -b shared/build.gradle’ executes the build script ‘build.gradle’ in the subdirectory ‘shared’ of your current directory. In that command you do not define a task which means Gradle would try to execute the default tasks declared in your build.
The notation ‘shared:build’ is a project path notation. In your example it means: Execute the task ‘build’ from the subproject ‘shared’. Gradle will also execute task dependencies.