build.gradle: more syntax uniformisation

Also don't do anythin in the task if serviceClasses either does not exist or is
empty.