When you're developing AEM applications, the OSGI bundle (and Manifest) is typically generated via the Felix maven-bundle-plugin.
The plugin writes your package imports
based on the java packages you import in your all of your Java code. If you are importing from a maven dependency, say Sling
the version for that import will be the package version from Sling
.
The issue you are having here could be one of two
- The package you are importing does not exists in OSGI (AEM Instance)
- There a mismatch between the version in your maven dependencies and the version in OSGI (AEM instance). Hence OSGI cannot resolve the version you are importing.
2.
is likely the case because sling is always bundled with AEM.
What can you do to debug/fix?
- You can go to http://localhost:4502/system/console/depfinder
and try your packages there to see what version is actually exported
in OSGI.
- Check wha versions of your dependencies you have in your
pom.xml
and make sure the OSGI version is within the range specified by the
manifest imports. You can use maven dependency tree to list all
your dependencies and their versions.
- This specific to AEM, if you are using
uber-jar
make sure you are
using the correct version for the correct AEM instance you're
running.
Note that in manifest imports the range [2.10,3)
means it accepts all versions between 2.10.0 and 3.0.0 but NOT including 3.0.0. In my experience, Maven bundle plugin will always write the range where the min is your maven dependency package version and the max is the next major
version.
Changing the imports manually:
This is not recommended and has very specific use cases, but you could manually tell the bundle plugin what version to add to the imports. See import-package instruction in the bundle plugin docs