Expand my Community achievements bar.

Embed Third party dependency using bnd-maven-plugin | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Embed Third party dependency using bnd-maven-plugin by AEM Learnings

Abstract

Two main instructions of bnd-maven-plugin that serves the purpose are detailed below.

-conditionalpackage
pick packages from respective library and copy them in the bundle. Any dependencies of those copied packages will also be copied if they match the selectors.
This means we need to explicitly list all the Java package names of desired dependency as part of this instruction (including its transitive dependencies)
More about conditionalpackage instruction from official docs - https://bnd.bndtools.org/instructions/conditionalpackage.html
-includeresource
For including resource inline
-includeresource: @artifactId-version.jar!/*
For embedding as a jar with an entry in bundle class path
-includeresource: artifactId-version.jar;lib:=true
For several other possible combinations for including the resource, please check - https://bnd.bndtools.org/instructions/includeresource.html
With complete understanding on these two instructions from official docs + based on how we would like the dependency to be included, we can use any one of the instruction with its respective options accordingly.

Sample plugin entry for the dependency jackson-dataformat-csv (Supports reading and writing CSV)
where ${jackson-dataformat-csv.version} in the instruction resolves to a maven property holding the artifact version (2.9.5) as defined in parent pom.xml.
conditionalpackage

biz.aQute.bnd
bnd-maven-plugin


bnd-process

bnd-process



Bundle-Category: Demo
Import-Package: javax.annotation;version=0.0.0,*
-exportcontents: ${packages;VERSIONED}
Sling-Model-Packages: com.aem.demoproject.core.models
-snapshot: ${tstamp;yyyyMMddHHmmssSSS}
-dsannotations-options: inherit
-conditionalpackage: com.fasterxml.jackson.dataformat.csv.*
Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin






org.apache.sling
org.apache.sling.caconfig.bnd-plugin
1.0.2


Read Full Blog

Embed Third party dependency using bnd-maven-plugin

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
1 Reply

Avatar

Level 1

Hi, The below snippet worked for me, Thanks

 

<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[
Import-Package: javax.annotation;version=0.0.0,*
-conditionalpackage: com.xx.*
-includeresource: @artifactid-versionnumber.jar!/
]]></bnd>
</configuration>
</execution>
</executions>
</plugin>