{"id":14421,"date":"2014-06-30T10:46:58","date_gmt":"2014-06-30T05:16:58","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=14421"},"modified":"2015-07-09T15:28:40","modified_gmt":"2015-07-09T09:58:40","slug":"register-groovy-class-as-componentservice-in-cq","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/register-groovy-class-as-componentservice-in-cq\/","title":{"rendered":"Register Groovy class as Component\/Service in CQ"},"content":{"rendered":"<p><a title=\"cq5 Developer\" href=\"http:\/\/www.tothenew.com\/wcm\/cq-aem-development-consulting\">Being a CQ5 developer<\/a>, I have to register components and services almost everyday. Knowing how powerful Groovy is, I wanted to replace all Java code with Groovy. First step towards it was being able to compile Groovy. I got it to work with the help of this <a title=\"Groovy with CQ5\" href=\"http:\/\/www.tothenew.com\/blog\/groovy-integration-with-cq5-in-maven\/\" target=\"_blank\">blog<\/a>.<\/p>\n<p>Although I was facing following problem even after this:<\/p>\n<p>&#8211; I was not able to register component as a service or component. Infact none of the SCR annotations seemed to work with Groovy. I had following maven-scr plugin configration.<\/p>\n<p>[html]<\/p>\n<p>    &lt;plugin&gt;<br \/>\n      &lt;groupId&gt;org.apache.felix&lt;\/groupId&gt;<br \/>\n      &lt;artifactId&gt;maven-scr-plugin&lt;\/artifactId&gt;<br \/>\n      &lt;executions&gt;<br \/>\n        &lt;execution&gt;<br \/>\n        &lt;id&gt;generate-scr-descriptor&lt;\/id&gt;<br \/>\n        &lt;goals&gt;<br \/>\n          &lt;goal&gt;scr&lt;\/goal&gt;<br \/>\n        &lt;\/goals&gt;<br \/>\n        &lt;\/execution&gt;<br \/>\n      &lt;\/executions&gt;<br \/>\n    &lt;\/plugin&gt;<\/p>\n<p>[\/html]<\/p>\n<p>Tried a lot of things for this and this is how I got it work(thanks to suggestions from a group):<\/p>\n<p>[html]<\/p>\n<p>   &lt;plugin&gt;<br \/>\n      &lt;groupId&gt;org.apache.felix&lt;\/groupId&gt;<br \/>\n      &lt;artifactId&gt;maven-scr-plugin&lt;\/artifactId&gt;<br \/>\n      &lt;configuration&gt;<br \/>\n        &lt;scanClasses&gt;true&lt;\/scanClasses&gt;<br \/>\n      &lt;\/configuration&gt;<br \/>\n      &lt;executions&gt;<br \/>\n        &lt;execution&gt;<br \/>\n          &lt;id&gt;generate-scr-descriptor&lt;\/id&gt;<br \/>\n          &lt;goals&gt;<br \/>\n            &lt;goal&gt;scr&lt;\/goal&gt;<br \/>\n          &lt;\/goals&gt;<br \/>\n        &lt;\/execution&gt;<br \/>\n      &lt;\/executions&gt;<br \/>\n   &lt;\/plugin&gt;<\/p>\n<p>[\/html]<\/p>\n<p>By default maven-scr plugin compiles only Java Classes. To make it aware of Groovy classes also, a configuration &#8220;scanClasses&#8221; has to be set to true.<\/p>\n<p>Updated:<\/p>\n<p>There are 2 more configuration changes that are needed:<\/p>\n<p>1) I had to change version of maven-scr-plugin from 1.7.4 to 1.17.0<\/p>\n<p>[java]<\/p>\n<p>&lt;plugin&gt;<br \/>\n&lt;groupId&gt;org.apache.felix&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;maven-scr-plugin&lt;\/artifactId&gt;<br \/>\n&lt;version&gt;1.17.0&lt;\/version&gt;<br \/>\n&lt;\/plugin&gt;<\/p>\n<p>[\/java]<\/p>\n<p>2) Change version of felix scr annotation to 1.9.8<\/p>\n<p>[java]<\/p>\n<p>&lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.apache.felix&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;org.apache.felix.scr.annotations&lt;\/artifactId&gt;<br \/>\n&lt;version&gt;1.9.8&lt;\/version&gt;<br \/>\n&lt;scope&gt;provided&lt;\/scope&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p>[\/java]<\/p>\n<p>Adding this code worked like a charm.<\/p>\n<p>Hope this helps CQ5 developers who love Groovy(like me. :))&#8230;<\/p>\n<p>Vivek Sachdeva<\/p>\n<p>CQ5 developer<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Being a CQ5 developer, I have to register components and services almost everyday. Knowing how powerful Groovy is, I wanted to replace all Java code with Groovy. First step towards it was being able to compile Groovy. I got it to work with the help of this blog. Although I was facing following problem even [&hellip;]<\/p>\n","protected":false},"author":48,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1],"tags":[4847,1207,9,1340],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14421"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=14421"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14421\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=14421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=14421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=14421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}