Dependency "cannot be resolved" for AEM Bundle: Why Your Bundle is Stalled in Installed State

Introduction
When we integrate a third-party dependency, we frequently encounter an issue where the bundle reaches the "Installed" state due to unresolved dependencies.
Whenever I encountered this issue, I did online research to find solutions. After dedicating some time to this, I was able to resolve the problem.
I will share my experiences and the methods I used to address the issue.
Approach 1: Manual installation of the dependency
The dependency package can be installed manually on the server
Access the “/crx/packmgr/index.jsp“
Upload and install the package
It will resolve the dependency issue
Cons:
This approach has a few issues:
The package needs to be manually installed across different environments.
When any team member pulls the latest code and deploys it locally, it may cause issues in the local build.
The package must be distributed to each team member to address their local build issues.
Approach 2: Installing the dependency as a plugin
Using Eclipse, the package can be converted into a plug-in.
We will try to resolve another dependency for “nimbusds“ dependency
Open Eclipse, File → New → Other → Plug-in from Existing JAR Archives
Click Next → Add External → Add the Jar
Click Next and update the details as required
Click Finish
Click Runtime → Add →
Select the necessary packages and click on “Add“.
Then go to MANIFEST.MF tab
Right-click on Project → Export → Deployable plug-ins and fragments → Next
Provide the path to save plugin and click on Finish
Once the jar is extracted, it can be added in two ways:
Directly install the package using the Felix console “/system/console/bundles“. This is not advisable.
Embed the jar in the code as explained further.
To embed the jar in the code: copy the jar at the following location:
ui.apps/src/main/content/jcr_root/apps/«project»/install/aem-nimbusds_1.0.0.jar
Add the following in the /ui.apps/pom.xml for “filevault-package-maven-plugin“ “embeddeds“ configuration
<embedded> <groupId>com.nimbusds</groupId> <artifactId>nimbus-jose-jwt</artifactId> <target>/apps/«project»/install</target> </embedded>
Build and deploy the code. now the dependency will be resolved.
Drawback: As the number of dependencies starts to increase, package size increases, and that results in consumption of more repository space with every deployment.
Approach 3: Using the “maven-bundle-plugin” plugin
This method is my preferred approach for deploying the dependency using the "maven-bundle-plugin."
I recommend creating a separate AEM project to manage the deployment of external dependencies because:
Adding multiple external dependencies will increase the bundle size.
This will extend deployment time and consume more repository space with each build.
The External Dependencies project can be deployed only when new dependencies are added.
The main project size and deployment time will not be impacted.
The AEM repository size will remain stable with each deployment of the main project.
We will solve the resolution issue for the following dependency:
Add the following configuration for the “maven-bundle-plugin“ plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.9</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>*;resolution:=optional</Import-Package>
<Export-Package>
com.adobe.aem.graphql.client.*
</Export-Package>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
Build and deploy the code. This should resolve the dependency issue, ensuring that all bundles are now in an active state.
I hope this helps fellow AEM developers quickly resolve dependency issues. Feel free to share which approach works best for you. I'd also love to hear if anyone has tackled this issue in a different way!
Subscribe to my newsletter
Read articles from Nitish Jain directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Nitish Jain
Nitish Jain
Nitish Jain is a seasoned Adobe AEM/CQ developer and architect with deep expertise in crafting connected digital experiences using the AEM technology stack. He has led the implementation of numerous large-scale AEM solutions across diverse industries, adhering to best practices and delivering scalable, high-performance architectures.