This post illustrate the ways of embedding third party dependency in AEM maven project.
Steps are mentioned considering the project structure to be followed for AEMasCS while the same can be followed for classic versions too.
Before we begin, I would like to explain the scenario of including a dependency in our AEM maven project.
When we would like to make use of an API that is not already available in our project, we look for that in maven-central repository and specify the dependency in main pom.xml and desired module's pom.xml file. (Lets say, AWS S3 Java SDK V2 dependency)
Upon updating the project in the IDE, we would see our class files (making use of those APIs) are compiled/build successfully without any errors.
Now, in the context of AEM/OSGi environment, when the same package and hence the bundle is deployed to AEM instance, dependencies that we added new might not be resolved/available in the OSGi as a bundle. Something like the below
This indicates that the added dependency is resolved in the context of Maven project and is not in the context of OSGi which paves way for the need of OSGi bundle of the desired dependency.
While this is possible with our existing core module itself which makes use of bnd-maven-plugin (plugin in recent archetype versions for building core module), some dependencies which are in turn dependent on other dependencies(referred to as transitive dependencies) could not be resolvable as bundle in OSGi. Hence the need for maven-bundle-plugin.
Creating an OSGi bundle out of third party non-osgi dependency using maven-bundle-plugin is explained in this blog post which is about building and deploying the OSGi bundle outside project code base as a standalone third party bundle.