Migration of SCR Annotations to DS Annotations Change is a rule of life, and if you are not updating yourself on current trends then you are constantly falling behind on new updates that can be essential to your system. With Adobe, they release a new version of AEM every year. Last year, they introduced SCR annotations, and now they are supporting DS annotations. From AEM 6.2 DS Annotations are supported,and it is highly recommended that you use these in the newer version of AEM.
Let’s see brief introduction of SCR Annotations and DS Annotations.
SCR Annotations: SCR stands for Service Component Runtime. The ”maven-scr-plugin” uses scr annotations from the corresponding subproject at Apache Felix. All annotations are in “org.apache.felix.scr.annotations” package. The Apache Felix SCR described by the OSGi Declarative Services Specification is implemented by the “org.apache.felix.scr” bundle.
SCR annotations do not support new feature from R6 and above. It is highly recommended to use OSGi annotations for Declarative Services instead.
DS Annotations: DS annotation is an official implementation from OSGi R6 (release 6) specification. It is also known as OSGi Declarative Services Annotations. Remember that declarative services are a compiled time process. For DS annotations to be effective, they must be handled during the build process. The migration is fairly easy and both annotation styles will work side-by-side while you complete the switch-over. So here will we discuss how to migrate from SCR annotation to DS annotations.
Plugin: For DS annotations we have to use “maven-bundle-plugin” instead of “maven-scr-plugin”. Version 3.2.0 or greater.
Dependencies: For DS annotations we need artifacts “org.osgi.service.metatype.annotations” and “org.osgi.service.component.annotations” instead “org.osgi.core” and “org.osgi.compendium”.
Java Package: In DS Annotation, package “org.apache.felix.scr.annotations.*” will be replaced with “org.osgi.service.component.annotations.*” and “org,osgi.service.metatype.annotations.*”.
Migration of Component and Services: We used to use @Component, @Service annotations in SCR Annotations while in DS annotation just have @Component annotation with the collaboration of all these annotations.
Migration of Custom OSGi Configuration: Major changes came in custom OSGi configuration. OSGi annotations provided a flexibility to create configuration in a separate interface and we can use it in any place.