How can I let a plugin depend on another module? Is it possible to let a plugin depend on a module (other than the declaring one)?
Use case: I want to create a field widget plugin that should depend on the 'date_all_day' contrib module, but I don't want the entire declaring module depend on this.
Is it possible to declare this in the annotation?
E.g.
/**
 * @FieldWidget(
 *   id = &quot;my_daterange&quot;,
 *   label = @Translation(&quot;Date and time range + All day&quot;),
 *   field_types = {&quot;daterange&quot;},
 *   dependencies = {&quot;date_all_day&quot;}
 * )
 */
class MyPlugin {...}

The plugin should only become available if both the declaring module and the dependency module are enabled.
Yes, this is possible.
You may declare a dependency on a module by using the &quot;provider&quot; key in the annotation. For your example, this would look like:
/**
 * @FieldWidget(
 *   id = &quot;my_daterange&quot;,
 *   label = @Translation(&quot;Date and time range + All day&quot;),
 *   field_types = {
 *     &quot;daterange&quot;
 *   },
 *   provider = &quot;date_all_day&quot;
 * )
 */
class MyPlugin {...}

Note that you can only list ONE provider, but of course that provider module can depend on other modules ...
This is a feature added to the DefaultPluginManager in order to allow plugins to declare a dependency on one (and only one) module. This only works for plugins that use a plugin manager derived from DefaultPluginManager.
Specifically, @FieldWidget plugins are managed by the WidgetPluginManager, which DOES subclass DefaultPluginManager, so this will work. (Most, if not all, core plugin managers subclass DefaultPluginManager.)