Maven dependency when using opencsv : Unable to start bundle

pn_2007

01-06-2020

I am trying to use opencsv in my AEM project. For that I have added the maven dependency as below in my core bundle pom.xml.

 

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
</dependency>

 

But after adding this dependency, my project bundle is showing installed status and I can see the below when anlaying the bundle.

org.apache.log -- Cannot be resolved

org.apache.avalon.framework.logger -- Cannot be resolved

 

Error.log :
missing requirement - Unresolved requirements: osgi.wiring.package; (osgi.wiring.package=org.apache.log)

 

Can someone help me understand if we need to add any more maven dependency when using opencsv in AEM?

 

 

Answer:

Thanks @ArpitVarshney for helping me fix this issue and Thank you @Albin_Issac for the valuable comments.
Adding the below dependencies in import-packages helped me resolve my issue. My bundles are up and running now.

<
plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
!org.apache.log,
!org.apache.avalon.framework.logger
</Import-Package>

<Embed-Dependency>*;
|opencsv
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
dependency maven osgi
View Entire Topic

Albin_Issac

MVP

01-06-2020

are you embedding opencsv dependency to the bundle? only adding the dependency to the pom.xml will not include the dependency to the bundle or server.

is there any issue related to com.opencsv packages in the bundle? Can you try embedding the opencsv bundle to the custom bundle package, please follow the below steps

For bnd-maven-plugin(if you are using latest bnd-maven-plugin)

Add new plug in to the core module

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependency</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>opencsv</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>

Modify the bnd-maven-plugin configurations as below(sample configuration, add your configurations)

<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<id>bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd><![CDATA[
Bundle-Category: demos
Import-Package: javax.annotation;version=0.0.0,com.opencsv,*
-exportcontents: ${packages;VERSIONED},\
com.opencsv.*

Include-Resource: target/dependency/opencsv-4.1.jar
Bundle-ClassPath: ., opencsv-4.1.jar
Sling-Model-Packages: demos.core.models
-snapshot: ${tstamp;yyyyMMddHHmmssSSS}
Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin


]]></bnd>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</plugin>

For maven-bundle-plugin(if you are using maven-bundle-plugin)

Add the below configurations to maven-bundle-plugin 

<Embed-Transitive>true</Embed-Transitive>

<Embed-Dependency>opencsv;scope=compile|runtime;inline=true</Embed-Dependency>