Split api and main classes to different source sets.

This means a separate api jar and no more inconsistencies between api
and core. (fix #1653)