May 26, 2020
Estimated Post Reading Time ~

How to Resolve a Maven-scr-Plugin Error in AEM

The idea for this article on resolving a Maven-scr-Plugin Error in AEM came about while building an AEM project using the Maven command. When we encountered this problem, we decided to explain the cause and the way to solve this error.

mvn clean install -P <Profile Name>

The Maven-scr-plugin error description is as shown below
[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) on project blog-bundle: SCR Descriptor parsing had failures (see log) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command

[ERROR]   mvn <goals> -rf :blog-bundle

Cause of Maven-scr-Plugin error
Most of the time this Maven-scr-pugin error occurs when you use the following two annotations together –
@SlingServlet and @Component same class.
For Example, if your coding syntax is
@SlingServlet(path="/bin/blog" extension="html")
@Component
Class TestServlet extends SlingSafeMethodsServlet { /*  ----------------------- */ }

In this case you will get that error, because @SlingServlet has “generateComponent” property and by default its value is “true” so ideally you don’t provide the @Component annotation.

How to resolve this Maven issue
There are two ways to resolve this issue –
Remove @Component annotation while creating Sling Servlet.
The issues with the first solution are –
Unable to activate this Sling Servlet immediately: The timing of activation of this Sling Servlet is totally dependent on Felix implementation. This means it may or may not be in active state after deploying the package.
We are not able to use immediate, enabled metatype and other properties provided by @Component.

The preferred way to use these annotations is
@SlingServlet(path="/bin/blog" extension="html", generateComponent=false)
@Component
Class TestServlet extends SlingSafeMethodsServlet { /*  ----------------------- */ }


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.