What you can do is set the unwanted binaries to not be buildable. For instance:
binaries.withType(StaticLibraryBinarySpec) {
buildable = false
}
setBuildable is an internal interface right now, but in the future, it will go away and there will be some sort of public interface for a binary that allows you to disable building it (e.g. something like “enabled = false”).