Expand my Community achievements bar.

AEM 6.3 JUnit dependency issue

Avatar

Level 2

I have added all the pom dependency with Junit, WCM io, Sling Jcr dependency.But still when i am running junit the below error is throwing when resource is adopting to page or node.

java.lang.NoSuchMethodError: org.osgi.framework.BundleContext.getServiceReference(Ljava/lang/Class;)Lorg/osgi/framework/ServiceReference;

    at org.apache.sling.testing.mock.sling.ThreadsafeMockAdapterManagerWrapper$AdapterManagerBundleContextFactory.getAdapterManager(ThreadsafeMockAdapterManagerWrapper.java:90)

    at org.apache.sling.testing.mock.sling.ThreadsafeMockAdapterManagerWrapper.getAdapter(ThreadsafeMockAdapterManagerWrapper.java:45)

    at org.apache.sling.api.adapter.SlingAdaptable.adaptTo(SlingAdaptable.java:104).

What could the reason for this exception.

1 Reply

Avatar

Level 3

AEM context will work only for the version 6.0.0 and above for osgi core and osgi cmpn. Update your pom dependency to fix the issue

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>osgi.core</artifactId>
    <version>6.0.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>osgi.cmpn</artifactId>
    <version>6.0.0</version>
    <scope>provided</scope>
</dependency>