Redmine Plugin Dependencies

I’ve been doing a lot of integration work with Redmine lately and needed one Redmine plugin to be depend on another plugin. So yesterday I added a new method to the Redmine plugin API called requires_redmine_plugin. It’s a simple method that will make sure another Redmine plugin is installed.

Using the API is simple, just call required_redmine_plugin in your init.rb where you register your plugin. For example, if I wanted to make the budget_plugin require the redmine_rate plugin I would register the budget_plugin with:

1
2
3
4
5
6
7
8
9
Redmine::Plugin.register :budget_plugin do
  name 'Budget'
  author 'Eric Davis'
  version '0.2.0'
 
  requires_redmine :version_or_higher => '0.8.0'
 
  requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0'
end

This follows the same format as the requires_redmine API so you can define the specific version in several ways:

  • Must have a specific version:
    1
    
    requires_redmine_plugin :redmine_rate, :version => '0.1.0'

    or

    1
    
    requires_redmine_plugin :redmine_rate, '0.1.0'
  • Must be at least a version:
    1
    
    requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0'
  • May be one of a few versions:
    1
    
    requires_redmine_plugin :redmine_rate, :version => ['0.1.0', '0.1.1', '0.1.2']

I like to define the version requirements as :version_or_higher since it will let the plugin run on newer versions without any changes.

Plugin load order

There is one gotcha with this API right now. The required_redmine_plugin method runs as Redmine is loading plugins alphabetically. This means if your plugin is loaded before the dependent plugin, there is a chance your plugin will not find the dependent plugin. To work around this, you will need to change the load order for the plugins so that the dependent plugin is loaded first.

The example from above is a perfect example of this, since the budget_plugin will be loaded before the redmine_rate plugin. By adding the following line to the config/additional_environment.rb the redmine_rate plugin will be loaded first, before any other plugins:

1
config.plugins = [ :redmine_rate, :all ]

This new API will be included in Redmine 0.9, so you will be able to take advantage of it with the next major release of Redmine.