While the Apache Felix Maven SCR Plugin is a great tool (see below), for developing OSGi components using Declarative Services you should use the official annotations from the OSGi R6 specification. The development of the Apache Felix SCR Plugin is in maintenance mode.
The examples and dependencies have been verified on AEM 6.3 Instance
Maven dependency changes:
In order to use the new OSGi annotations, we need to add following dependencies to pom.xml.
org.osgi osgi.core 6.0.0 provided org.osgi osgi.cmpn 6.0.0 provided org.osgi osgi.annotation 6.0.1 provided
Use latest version of maven-bundle-plugin (>=3.2.0)
For a project upgrading from Felix to DS annotations, you can remove following:
- All Felix dependencies. Example:
- maven-scr-plugin: is required to resolve felix annotations at build time
You can choose to update java files at once, or one-by-one.
- Incase you wish to modify all files together, then remove felix dependencies and plugins. The IDE would now recognize all the files that need modifcation.
- However, if you wish to change files one-by-one, then you can keep both DS and Felix dependencies in pom.xml. A bundle with both types of annotations would still be good. Once all the code changes are done, you should remove all felix dependencies.
How to identify the changes:
You can easily identify the files, by looking for package imports of “org.apache.felix.scr.annotations.*”.
We would be using the following packages instead:
For more details on code changes involved, please visit the specific links:
- Component, property and configurations
- Service and References
Verify annotation resolution
To verify if the DS annotation is generated:
- decompile the jar created after mvn clean install
- Check for the Service description available below /OSGI-INF/ folder