[Solved] Problem register module with submodules

I’m developing an addon, which is really two addons combined into one. The addon is a package with the following structure:

foo:
    bar
    baz
    shared
 

The packages bar and baz are defining a lot of classes, whereas shared contains code that used by both the other packages. The reason why I don’t want to make two separate addons is that the shared code is quite large, and I don’t want to duplicate the code. My problem is that when I try to register the submodules, I get the error message:

Exception: register_module(‘foo.bar’): defines no classes

init.py in foo:

bl_info = {...}
    
def register:
    bar.register()
    baz.register()
       
def unregister:
    bar.unregister()
    baz.unregister()
if __name__ == "__main__":
    register()

init.py in bar:

Define classes...
def register():
    bpy.utils.register_module(__name__)
def unregister():
    bpy.utils.unregister_module(__name__)
    

It works to register the classes explicitly with bpy.utils.register_class, but this becomes messy to maintain.
A workaround would be to make two separate addons, include the shared package into the bar addon, and let baz import from bar. However, this creates an inter-addon dependence which could lead to confusion.

you can’t register scripts which do not contain any classes deriving from bpy.types (simply don’t, it’s not necessary)

The top module does not define any classes, but foo.bar and foo.baz do. Anyway, I found the solution: remove registration from the submodules and call register_module(name) in the top module instead.