Hi,
I have an older server/DC plugin which uses <DynamicImport-Package>
statements in the pom.xml and its Java code takes care of handling 3rd-party dependencies properly, i.e. only using those code paths when the 3rd-party marketplace app is installed and activated. Everything works as intended. So far, so good.
Now, I want to update my plugin to use Spring-Scanner. Previously, I did that in other plugins successfully. This is the 1st time that a plugin uses dynamic dependencies. I took proper care of NOT declaring any of my classes, which use classes from the 3rd-party app, as @Component
or @Autowired
, because I know that this cannot work if the the 3rd-party app is not installed. But nonetheless I run into “missing dependency” errors when the 3rd-party app is not installed/activated. (Everything is working fine if the 3rd-party app is installed/activated.) I debugged and gathered the following:
- File /META-INF/MANIFEST.MF contains
DynamicImport-Package
statements, as defined in my pom.xml. Good. - But /META-INF/MANIFEST.MF also contains
Import-Package
statements for the dynamic packages. Not good! - I deleted all
DynamicImport-Package
statements in pom.xml -> unwantedImport-Package
statements still present! - I deleted all references relating to classes from the dynamic 3rd-party app -> unwanted
Import-Package
statements are gone. - I re-added
DynamicImport-Package
statements in pom.xml -> unwantedImport-Package
statements still gone. - I re-added all references relating to classes from the dynamic 3rd-party app -> unwanted
Import-Package
statements are back again! - I removed 1 specific reference to a 3rd-party class -> the
Import-Package
statement for that class’s package is gone!
After long thought my only explanation is that Spring-Scanner adds Import-Package
statements for each class it finds, even for dynamic dependencies. This is bad! How can I make sure dynamic dependency stay dynamic that way, without manually adjusting /META-INF/MANIFEST.MF? Can I exclude certain classes from scanning? Can I exclude certain 3rd-party packages from being added as Import-Package
statements? What else can I do to fix this, apart from not using Spring-Scanner?
Thanks a bunch,
Andreas