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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. Declarative services require maven-bundle-plugin version 3.2.0 or greater
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
- Verify that description of your Service is available below /OSGI-INF/ folder