Dependencies among plugins

Mandatory dependencies

A plugin can declare dependencies to other plugins. When plugin X depends on Y, X can see all the classes in Y, as well as Y's libraries and dependencies. If one of the mandatory dependencies is unavailable then the plugin will be disabled and can not be used.

To declare a dependency, add the following entry to plugin pom.xml

<dependency>
  <groupId>org.jvnet.hudson.plugins</groupId>
  <artifactId>javanet-uploader</artifactId>
  <version>1.5</version>
</dependency>

The groupId, artifactId, version needs to be changed according to what you want to depend on.

Optional dependencies

It is possible to declare dependencies to other plugins as optional. If one of the optional dependencies is unavailable then the plugin will not be disabled.

To declare an optional dependency, add the <optional/> tag to the declared dependency in the plugin pom.xml

<dependency>
  <groupId>org.jvnet.hudson.plugins</groupId>
  <artifactId>javanet-uploader</artifactId>
  <version>1.5</version>
  <optional>true/optional>
</dependency>

If any of the classes in the unavailable optional dependencies are used in the plugin a ClassNotFoundException will be thrown. To determine if an optional dependency is installed, the Hudson.getPlugin(String) method can be used.

if (Hudson.getPlugin("javanet-uploader") != null) {
    // use classes in the "javanet-uploader" plugin
}

Labels

  Edit Labels
(None)