Native build: using buildable to disable certain flavors

I have a multi-project native build with some common flavours defined that are applicable to nearly all sub-projects. However, one sub-project cannot build one of those flavours, so I’m trying to disable the corresponding build:

binaries.withType(SharedLibraryBinarySpec) {
if ( flavor != flavors.flavorToKeep) {
buildable = false

But this isn’t having any effect (the tasks relevant to that build, such as the compile task, are still getting executed), and I can’t see why. Am I wrong to expect them to be skipped even if something else tries to pull them into the task graph?

Thanks for any insight.