I was running into the exact same issue:
org.gradle.api.InvalidUserDataException: Project directory ‘Users/Shared/myProject/theDirectory/src/test is not part of the build defined by settings file ‘Users/Shared/myProject/theDirectory/settings.gradle.
The issue was I was running gradle from a terminal window that was based too far down in the directory structure.
The FIX: simply Change Directories in the terminal window cd ..
So for me I simply backed up to directory levels to: “myProject” folder and boom…simple gradle works.