Fix for GRADLE-2974 and GRADLE-3031

Ensure that tasks excluded using -x command line option are indeed excluded when they are a dependency of multiple tasks.