How to remove unused sourcesets

Hi,

I’m trying to remove unused sourcesets from subproject using the following code:

model {
    components {
        all {
            getSources().values().removeIf({ it instanceof ObjectiveCppSourceSet })
            getSources().values().removeIf({ it instanceof ObjectiveCSourceSet })
        }
    }
}

But it does not work.