To build different target from multi-project which should has different includes in settings.gradle

for exmaple,
there is three sub-project, I call them A, B, C

to build target B
settings.gradle should be:
include ‘:A’
include ‘:B’

to build target C
settings.gradle should be:
include ‘:A’
include ‘:C’

how can I config settings.gradle automatically by add some groovy code in settings or defined two tasks, one is to build target B and the other is to build target C