You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Flavio <fb...@gmail.com> on 2023/03/06 13:28:41 UTC

Unable to solve "No OSGi SCR metadata found for class"

Hi Everyone,

I know there are tons of discussions and resources on the Internet, but
after many days trying to add the missing suggested dependencies, adjusting
the pom.xml with plugins and configurations I have no more ideas on how to
solve this.

I would kindly ask your support in order to achieve OSGi framework Unit
testing in my project.
One of the main suggestions I have found is this one:
https://stackoverflow.com/questions/48551036/exception-on-service-activation-in-mock-osgi-context

Still no luck!

Can somebody help me with this please?

Here's the error I get once I try to build via maven:

org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
metadata found for class com.test.ConfigurationService
at
org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:79)
at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:314)
at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:325)

-- 
Flavio

RE: Unable to solve "No OSGi SCR metadata found for class"

Posted by Stefan Seifert <St...@diva-e.com.INVALID>.
personally i'm using eclipse, which has incremental build support which is used by bnd-maven-plugin to automatically update the metadata files on each class change and works very well. not sure if Intellij IDE supports something similar.

doing this automatically with the osgi-mock/sling-mock logic is not trivial: detecting missing metadata is easy, but invoking a bnd process out of the unit test context respecting all custom project settings from the POM is either very difficult to do it right, or very expensive e.g. if you just trigger a full maven call.

stefan

> -----Original Message-----
> From: Roy Teeuwen <ro...@teeuwen.be>
> Sent: Monday, March 6, 2023 10:05 PM
> To: Sling Developers <de...@sling.apache.org>
> Subject: Re: Unable to solve "No OSGi SCR metadata found for class"
> 
> @Stefan, is there any way that it is feasible for Intellij IDE to run the
> sling mock unit tests without first doing a compile with maven (and thus
> triggering the bnd-maven-plugin to create the OSG-INF files)? It would be
> handy if SlingContext could compile them "at runtime" of the junit test if
> they aren't available

Re: Unable to solve "No OSGi SCR metadata found for class"

Posted by Roy Teeuwen <ro...@teeuwen.be>.
@Stefan, is there any way that it is feasible for Intellij IDE to run the sling mock unit tests without first doing a compile with maven (and thus triggering the bnd-maven-plugin to create the OSG-INF files)? It would be handy if SlingContext could compile them "at runtime" of the junit test if they aren't available

> On 6 Mar 2023, at 15:09, Stefan Seifert <St...@diva-e.com.INVALID> wrote:
> 
> hello flavio.
> 
> are you getting this error running maven on the command line, or only within your IDE?
> 
> if you are using bnd-maven-plugin, this should work automatically. there are some required configuration options for maven-bundle-plugin [1], but this plugin is outdated and you should migrate [2].
> 
> stefan
> 
> 
> [1] https://wcm-io.atlassian.net/l/cp/vcqy50qF
> [2] https://wcm-io.atlassian.net/l/cp/2tPaJN0X
> 
>> -----Original Message-----
>> From: Flavio <fb...@gmail.com>
>> Sent: Monday, March 6, 2023 2:29 PM
>> To: dev@sling.apache.org
>> Subject: Unable to solve "No OSGi SCR metadata found for class"
>> 
>> Hi Everyone,
>> 
>> I know there are tons of discussions and resources on the Internet, but
>> after many days trying to add the missing suggested dependencies,
>> adjusting the pom.xml with plugins and configurations I have no more ideas
>> on how to solve this.
>> 
>> I would kindly ask your support in order to achieve OSGi framework Unit
>> testing in my project.
>> One of the main suggestions I have found is this one:
>> https://stackoverflow.com/questions/48551036/exception-on-service-
>> activation-in-mock-osgi-context
>> 
>> Still no luck!
>> 
>> Can somebody help me with this please?
>> 
>> Here's the error I get once I try to build via maven:
>> 
>> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
>> metadata found for class com.test.ConfigurationService at
>> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(Osgi
>> ServiceUtil.java:79)
>> at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:314)
>> at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:325)
>> 
>> --
>> Flavio


Re: Unable to solve "No OSGi SCR metadata found for class"

Posted by Flavio <fb...@gmail.com>.
I'm wondering about it too..
Unfortunately I inherited this code, and need to add this unit testing now.
I prefer to not ask this to myself too :D
Simply.. this code works but unit test were never implemented before.
Thanks for the samples!

Il giorno lun 6 mar 2023 alle ore 16:56 Stefan Seifert
<St...@diva-e.com.invalid> ha scritto:

> this should not be required ... i'm wondering how your project was working
> before deployed in an OSGi container (before adding unit tests) without
> having bnd-maven-plugin or maven-bundle-plugin in place.
>
> here is an example for a bnd-maven-plugin configuration - with a lot of
> extra stuff added, most is not needed for simple use cases:
>
> https://github.com/wcm-io/io.wcm.maven.aem-global-parent/blob/de8c3d2cdc0347b0c5d934696da9b8165fbf7d0a/pom.xml#L249-L309
>
> stefan
>
> > -----Original Message-----
> > From: Flavio <fb...@gmail.com>
> > Sent: Monday, March 6, 2023 4:40 PM
> > To: dev@sling.apache.org
> > Subject: Re: Unable to solve "No OSGi SCR metadata found for class"
> >
> > Hello!
> >
> > I have understood the root cause of the problem.
> > Adding the following file solved the issue and I was able to run the test
> > flawlessly:
> > src/test/resources/OSGI-INF/serviceComponents.xml
> >
> > Thanks!
> >
> > Il giorno lun 6 mar 2023 alle ore 15:21 Flavio <fb...@gmail.com> ha
> > scritto:
> >
> > > Hi Stefan!
> > >
> > > Thanks for replying. I'm getting this error on the command line.
> > > Consider that I am adding for the first time JUnits to my osgi project
> > > so I have to introduce also this bnd-maven-plugin.
> > > I added the following part to my pom.xml into the plugins section but
> > > still no luck:
> > >
> > > <plugin>
> > >    <groupId>biz.aQute.bnd</groupId>
> > >    <artifactId>bnd-maven-plugin</artifactId>
> > > </plugin>
> > > <plugin>
> > >    <groupId>org.apache.maven.plugins</groupId>
> > >    <artifactId>maven-jar-plugin</artifactId>
> > >    <configuration>
> > >       <archive>
> > >          <manifestFile>${project.build.outputDirectory}/META-
> > INF/MANIFEST.MF</manifestFile>
> > >       </archive>
> > >    </configuration>
> > > </plugin>
> > >
> > >
> > > Flavio
> > >
> > > Il giorno lun 6 mar 2023 alle ore 15:09 Stefan Seifert
> > > <St...@diva-e.com.invalid> ha scritto:
> > >
> > >> hello flavio.
> > >>
> > >> are you getting this error running maven on the command line, or only
> > >> within your IDE?
> > >>
> > >> if you are using bnd-maven-plugin, this should work automatically.
> > >> there are some required configuration options for maven-bundle-plugin
> > >> [1], but this plugin is outdated and you should migrate [2].
> > >>
> > >> stefan
> > >>
> > >>
> > >> [1] https://wcm-io.atlassian.net/l/cp/vcqy50qF
> > >> [2] https://wcm-io.atlassian.net/l/cp/2tPaJN0X
> > >>
> > >> > -----Original Message-----
> > >> > From: Flavio <fb...@gmail.com>
> > >> > Sent: Monday, March 6, 2023 2:29 PM
> > >> > To: dev@sling.apache.org
> > >> > Subject: Unable to solve "No OSGi SCR metadata found for class"
> > >> >
> > >> > Hi Everyone,
> > >> >
> > >> > I know there are tons of discussions and resources on the Internet,
> > >> > but after many days trying to add the missing suggested
> > >> > dependencies, adjusting the pom.xml with plugins and configurations
> > >> > I have no more
> > >> ideas
> > >> > on how to solve this.
> > >> >
> > >> > I would kindly ask your support in order to achieve OSGi framework
> > >> > Unit testing in my project.
> > >> > One of the main suggestions I have found is this one:
> > >> > https://stackoverflow.com/questions/48551036/exception-on-service-
> > >> > activation-in-mock-osgi-context
> > >> >
> > >> > Still no luck!
> > >> >
> > >> > Can somebody help me with this please?
> > >> >
> > >> > Here's the error I get once I try to build via maven:
> > >> >
> > >> > org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi
> > >> > SCR metadata found for class com.test.ConfigurationService at
> > >> >
> > >> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate
> > >> (Osgi
> > >> > ServiceUtil.java:79)
> > >> > at
> > >> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:31
> > >> 4)
> > >> > at
> > >> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:32
> > >> 5)
> > >> >
> > >> > --
> > >> > Flavio
> > >>
> > >
> > >
> > > --
> > > Flavio
> > >
> >
> >
> > --
> > Flavio
>


-- 
Flavio

RE: Unable to solve "No OSGi SCR metadata found for class"

Posted by Stefan Seifert <St...@diva-e.com.INVALID>.
this should not be required ... i'm wondering how your project was working before deployed in an OSGi container (before adding unit tests) without having bnd-maven-plugin or maven-bundle-plugin in place.

here is an example for a bnd-maven-plugin configuration - with a lot of extra stuff added, most is not needed for simple use cases:
https://github.com/wcm-io/io.wcm.maven.aem-global-parent/blob/de8c3d2cdc0347b0c5d934696da9b8165fbf7d0a/pom.xml#L249-L309

stefan

> -----Original Message-----
> From: Flavio <fb...@gmail.com>
> Sent: Monday, March 6, 2023 4:40 PM
> To: dev@sling.apache.org
> Subject: Re: Unable to solve "No OSGi SCR metadata found for class"
> 
> Hello!
> 
> I have understood the root cause of the problem.
> Adding the following file solved the issue and I was able to run the test
> flawlessly:
> src/test/resources/OSGI-INF/serviceComponents.xml
> 
> Thanks!
> 
> Il giorno lun 6 mar 2023 alle ore 15:21 Flavio <fb...@gmail.com> ha
> scritto:
> 
> > Hi Stefan!
> >
> > Thanks for replying. I'm getting this error on the command line.
> > Consider that I am adding for the first time JUnits to my osgi project
> > so I have to introduce also this bnd-maven-plugin.
> > I added the following part to my pom.xml into the plugins section but
> > still no luck:
> >
> > <plugin>
> >    <groupId>biz.aQute.bnd</groupId>
> >    <artifactId>bnd-maven-plugin</artifactId>
> > </plugin>
> > <plugin>
> >    <groupId>org.apache.maven.plugins</groupId>
> >    <artifactId>maven-jar-plugin</artifactId>
> >    <configuration>
> >       <archive>
> >          <manifestFile>${project.build.outputDirectory}/META-
> INF/MANIFEST.MF</manifestFile>
> >       </archive>
> >    </configuration>
> > </plugin>
> >
> >
> > Flavio
> >
> > Il giorno lun 6 mar 2023 alle ore 15:09 Stefan Seifert
> > <St...@diva-e.com.invalid> ha scritto:
> >
> >> hello flavio.
> >>
> >> are you getting this error running maven on the command line, or only
> >> within your IDE?
> >>
> >> if you are using bnd-maven-plugin, this should work automatically.
> >> there are some required configuration options for maven-bundle-plugin
> >> [1], but this plugin is outdated and you should migrate [2].
> >>
> >> stefan
> >>
> >>
> >> [1] https://wcm-io.atlassian.net/l/cp/vcqy50qF
> >> [2] https://wcm-io.atlassian.net/l/cp/2tPaJN0X
> >>
> >> > -----Original Message-----
> >> > From: Flavio <fb...@gmail.com>
> >> > Sent: Monday, March 6, 2023 2:29 PM
> >> > To: dev@sling.apache.org
> >> > Subject: Unable to solve "No OSGi SCR metadata found for class"
> >> >
> >> > Hi Everyone,
> >> >
> >> > I know there are tons of discussions and resources on the Internet,
> >> > but after many days trying to add the missing suggested
> >> > dependencies, adjusting the pom.xml with plugins and configurations
> >> > I have no more
> >> ideas
> >> > on how to solve this.
> >> >
> >> > I would kindly ask your support in order to achieve OSGi framework
> >> > Unit testing in my project.
> >> > One of the main suggestions I have found is this one:
> >> > https://stackoverflow.com/questions/48551036/exception-on-service-
> >> > activation-in-mock-osgi-context
> >> >
> >> > Still no luck!
> >> >
> >> > Can somebody help me with this please?
> >> >
> >> > Here's the error I get once I try to build via maven:
> >> >
> >> > org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi
> >> > SCR metadata found for class com.test.ConfigurationService at
> >> >
> >> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate
> >> (Osgi
> >> > ServiceUtil.java:79)
> >> > at
> >> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:31
> >> 4)
> >> > at
> >> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:32
> >> 5)
> >> >
> >> > --
> >> > Flavio
> >>
> >
> >
> > --
> > Flavio
> >
> 
> 
> --
> Flavio

Re: Unable to solve "No OSGi SCR metadata found for class"

Posted by Flavio <fb...@gmail.com>.
Hello!

I have understood the root cause of the problem.
Adding the following file solved the issue and I was able to run the test
flawlessly:
src/test/resources/OSGI-INF/serviceComponents.xml

Thanks!

Il giorno lun 6 mar 2023 alle ore 15:21 Flavio <fb...@gmail.com> ha
scritto:

> Hi Stefan!
>
> Thanks for replying. I'm getting this error on the command line.
> Consider that I am adding for the first time JUnits to my osgi project so
> I have to introduce also this bnd-maven-plugin.
> I added the following part to my pom.xml into the plugins section but
> still no luck:
>
> <plugin>
>    <groupId>biz.aQute.bnd</groupId>
>    <artifactId>bnd-maven-plugin</artifactId>
> </plugin>
> <plugin>
>    <groupId>org.apache.maven.plugins</groupId>
>    <artifactId>maven-jar-plugin</artifactId>
>    <configuration>
>       <archive>
>          <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
>       </archive>
>    </configuration>
> </plugin>
>
>
> Flavio
>
> Il giorno lun 6 mar 2023 alle ore 15:09 Stefan Seifert
> <St...@diva-e.com.invalid> ha scritto:
>
>> hello flavio.
>>
>> are you getting this error running maven on the command line, or only
>> within your IDE?
>>
>> if you are using bnd-maven-plugin, this should work automatically. there
>> are some required configuration options for maven-bundle-plugin [1], but
>> this plugin is outdated and you should migrate [2].
>>
>> stefan
>>
>>
>> [1] https://wcm-io.atlassian.net/l/cp/vcqy50qF
>> [2] https://wcm-io.atlassian.net/l/cp/2tPaJN0X
>>
>> > -----Original Message-----
>> > From: Flavio <fb...@gmail.com>
>> > Sent: Monday, March 6, 2023 2:29 PM
>> > To: dev@sling.apache.org
>> > Subject: Unable to solve "No OSGi SCR metadata found for class"
>> >
>> > Hi Everyone,
>> >
>> > I know there are tons of discussions and resources on the Internet, but
>> > after many days trying to add the missing suggested dependencies,
>> > adjusting the pom.xml with plugins and configurations I have no more
>> ideas
>> > on how to solve this.
>> >
>> > I would kindly ask your support in order to achieve OSGi framework Unit
>> > testing in my project.
>> > One of the main suggestions I have found is this one:
>> > https://stackoverflow.com/questions/48551036/exception-on-service-
>> > activation-in-mock-osgi-context
>> >
>> > Still no luck!
>> >
>> > Can somebody help me with this please?
>> >
>> > Here's the error I get once I try to build via maven:
>> >
>> > org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
>> > metadata found for class com.test.ConfigurationService at
>> >
>> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(Osgi
>> > ServiceUtil.java:79)
>> > at
>> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:314)
>> > at
>> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:325)
>> >
>> > --
>> > Flavio
>>
>
>
> --
> Flavio
>


-- 
Flavio

Re: Unable to solve "No OSGi SCR metadata found for class"

Posted by Flavio <fb...@gmail.com>.
Hi Stefan!

Thanks for replying. I'm getting this error on the command line.
Consider that I am adding for the first time JUnits to my osgi project so I
have to introduce also this bnd-maven-plugin.
I added the following part to my pom.xml into the plugins section but still
no luck:

<plugin>
   <groupId>biz.aQute.bnd</groupId>
   <artifactId>bnd-maven-plugin</artifactId>
</plugin>
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <configuration>
      <archive>
         <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
      </archive>
   </configuration>
</plugin>


Flavio

Il giorno lun 6 mar 2023 alle ore 15:09 Stefan Seifert
<St...@diva-e.com.invalid> ha scritto:

> hello flavio.
>
> are you getting this error running maven on the command line, or only
> within your IDE?
>
> if you are using bnd-maven-plugin, this should work automatically. there
> are some required configuration options for maven-bundle-plugin [1], but
> this plugin is outdated and you should migrate [2].
>
> stefan
>
>
> [1] https://wcm-io.atlassian.net/l/cp/vcqy50qF
> [2] https://wcm-io.atlassian.net/l/cp/2tPaJN0X
>
> > -----Original Message-----
> > From: Flavio <fb...@gmail.com>
> > Sent: Monday, March 6, 2023 2:29 PM
> > To: dev@sling.apache.org
> > Subject: Unable to solve "No OSGi SCR metadata found for class"
> >
> > Hi Everyone,
> >
> > I know there are tons of discussions and resources on the Internet, but
> > after many days trying to add the missing suggested dependencies,
> > adjusting the pom.xml with plugins and configurations I have no more
> ideas
> > on how to solve this.
> >
> > I would kindly ask your support in order to achieve OSGi framework Unit
> > testing in my project.
> > One of the main suggestions I have found is this one:
> > https://stackoverflow.com/questions/48551036/exception-on-service-
> > activation-in-mock-osgi-context
> >
> > Still no luck!
> >
> > Can somebody help me with this please?
> >
> > Here's the error I get once I try to build via maven:
> >
> > org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
> > metadata found for class com.test.ConfigurationService at
> >
> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(Osgi
> > ServiceUtil.java:79)
> > at
> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:314)
> > at
> org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:325)
> >
> > --
> > Flavio
>


-- 
Flavio

RE: Unable to solve "No OSGi SCR metadata found for class"

Posted by Stefan Seifert <St...@diva-e.com.INVALID>.
hello flavio.

are you getting this error running maven on the command line, or only within your IDE?

if you are using bnd-maven-plugin, this should work automatically. there are some required configuration options for maven-bundle-plugin [1], but this plugin is outdated and you should migrate [2].

stefan


[1] https://wcm-io.atlassian.net/l/cp/vcqy50qF
[2] https://wcm-io.atlassian.net/l/cp/2tPaJN0X

> -----Original Message-----
> From: Flavio <fb...@gmail.com>
> Sent: Monday, March 6, 2023 2:29 PM
> To: dev@sling.apache.org
> Subject: Unable to solve "No OSGi SCR metadata found for class"
> 
> Hi Everyone,
> 
> I know there are tons of discussions and resources on the Internet, but
> after many days trying to add the missing suggested dependencies,
> adjusting the pom.xml with plugins and configurations I have no more ideas
> on how to solve this.
> 
> I would kindly ask your support in order to achieve OSGi framework Unit
> testing in my project.
> One of the main suggestions I have found is this one:
> https://stackoverflow.com/questions/48551036/exception-on-service-
> activation-in-mock-osgi-context
> 
> Still no luck!
> 
> Can somebody help me with this please?
> 
> Here's the error I get once I try to build via maven:
> 
> org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
> metadata found for class com.test.ConfigurationService at
> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(Osgi
> ServiceUtil.java:79)
> at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:314)
> at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:325)
> 
> --
> Flavio