com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle - Adobe Experience Manager(AEM)
I was able compile and deploy the bundle successfully with gson dependency but the bundle is not getting started with the error "com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle" in Adobe Experience Manager(AEM)The root cause of the problem is the gson jar is not available in the server for bundle access.
This issue can be resolved by following any of the below approach.
1. Export the gson package - com.google.gson.*
<dependency><groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>com.sample.activator.Activator</Bundle-Activator>
<Import-Package>*,com.sample.*</Import-Package>
<Export-Package>com.sample.*,com.google.gson.*</Export-Package>
<Bundle-SymbolicName>com.sample</Bundle-SymbolicName>
<Bundle-Vendor>Sample</Bundle-Vendor>
<Bundle-Category>Sample</Bundle-Category>
<Embed-Directory>dependencies</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
2. Add the gson jar in the bundle class path
Specify the gson dependency scpes as compile or runtime(compile is the default scope)<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency
The gson jar will be included in the bundle classpath.
The dependencies with what are all the scopes are included in the bundle classpath is configured in maven-bundle-plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>