build.gradle: simplification

Use URI to get the relative path of the class. Much simpler than using
substrings everywhere!
build.gradle: complete service file writing now done

All that is left to do is make a task out of it.