You can point to a build file and execute the task inside that build file using the below command.
gradle --build-file <file_name>.gradle -q <task_name> gradle -b <file_name>.gradle -q <task_name>
You can execute task in any project directory by using the below command
gradle --project-dir <project_directory> -q <task_name>
You can execute both of above command together sample below