build.gradle: change generateServiceFiles dependencies

Make it depend on compileJava, and make processResources depend on it.

Before, the dependent tasks were respectively classes and jar. But the classes
task is actually performed _after_ compileJava; and make jar depend on it means
it won't be run, for instance, on tests. Which is not good!
Factorize common elements in common.gradle; import it in build.gradle.
Put all serviceloader file creation in common.gradle