Separate OSGI services api from implementation
It is considered best practice to create separate OSGi bundles for the API and implementation of a service. I use multi-module maven projects so the modules are arranged like this :-
parent |- all |- config |- content |- services |- taglib |- view
The 'services' module is where (up until now) I create the service class and its api typically under package names like :-
my.company.domain.aem.services.api - IHelloWorld.java (interface)
my.company.domain.aem.services - HelloWorld.java (implementation)
However, when you do that and use the maven-bundle-plugin BOTH of these classes will end up in the SAME bundle since thats the default behaviour (scans all src).
Whilst its easy to ensure that only the interface is EXPORTED, it really ought to be in its own bundle.
It *is* possible to change that behaviour and create 2 bundles using either a separate profile or separate <execution> configuration, but both of these are generally considered to be an anti-pattern.
The only other approach appears to be to create an additional module with it own POM and thus its own build output. So in addition to the above structure add a new module ;-
|- services-api (and move my.company.domain.aem.services.api - IHelloWorld.java (interface) into it)
That also means that you need to add a dependency in the 'services' module to 'services-api' module (also to taglib if it happens to use the service)
I can certainly get this approach to work, but I thought it was worth asking whether anyone else does this differently ?
Kind Regards
Fraser.