I have a plugin A with an optional dependency on classes from a plugin B.
I have a control over the source code of a plugin B only.
The workflow I am trying to implement is following:
- If plugin B is enabled → use classes from it and execute dependent code
- If plugin B disabled/not installed → skip use of plugin B classes in the dependent code
Steps that I took so far:
- In my pom.xml for plugin A the dependency artifact marked as provided
- In the Import section the package is listed as optional.
- I have a class (component) with a constructor where I take a class from plugin B and set it as a field of the instance:
@Component
public class MyEventListener implements InitializingBean, DisposableBean {
@Autowired
MyEventListener(@ComponentImport PluginBClass dataManager) {
this.dataManager = dataManager;
this.MyIndexer = new MyIndexer(edataManager);
}
{
//use here dependency if it is available
}
}
When I disable plugin B and try to enable plugin A, UPM says that some of dependencies are not available and the plugin remains disabled. Is there any approach to load the dependency conditionally only if the plugin B is enabled.