That’s because ‘build’ depends on ‘check’. I’d be reluctant to make ‘check’ behave differently than ‘build’ in this regard, because it is against the expected behavior of these tasks. Instead I would consider adding my own variant of a ‘check’ task, targeted at the specific needs.
If you really want ‘check’ and ‘build’ to behave differently in terms of which CheckStyle tasks they run, you’ll have to resort to conditional configuration using the ‘gradle.taskGraph.whenReady’ idiom. Nevertheless, ‘checkstyle.sourceSets’ remains the way to go.
Abstracting from the concrete problem, whenever possible it’s better to add only what’s needed in the first place, rather than adding too much and then trying to compensate by removing some of it. This applies to many areas of Gradle (plugins, tasks, dependencies, etc.). It’s also usually better to provide multiple variants of something, rather than to make the same thing behave differently under different circumstances (the ‘check’ task in this case).