First, you’ll learn how to create a configuration with no scope declaration.
This automatically scopes your configuration to SYSTEM
.
-
Create a Java interface to represent the configuration and its default values. Using a Java interface allows for an advanced type system for each configuration option. Here is the configuration interface for the Liferay Forms application:
@Meta.OCD( id = "com.liferay.dynamic.data.mapping.form.web.configuration.DDMFormWebConfiguration", localization = "content/Language", name = "ddm-form-web-configuration-name" ) public interface DDMFormWebConfiguration { @Meta.AD( deflt = "1", description = "autosave-interval-description", name = "autosave-interval-name", required = false ) public int autosaveInterval(); @Meta.AD( deflt = "descriptive", name = "default-display-view", optionLabels = {"Descriptive", "List"}, optionValues = {"descriptive", "list"}, required = false ) public String defaultDisplayView(); }
This defines two configuration options, the autosave interval (with a default of one minute) and the default display view, which can be descriptive or list, but defaults to descriptive. Here’s what the two Java annotations in the above snippet do:
Meta.OCD: Registers this class as a configuration with a specific id. The ID must be the fully qualified configuration class name.
Meta.AD: Specifies optional metadata about the field, such as whether it’s a required field or if it has a default value. Note that if you set a field as required and don’t specify a default value, the system administrator must specify a value in order for your application to work properly. Use the
deflt
property to specify a default value.The fully-qualified name of the
Meta
class above isaQute.bnd.annotation.metatype.Meta
. For more information about this class and theMeta.OCD
andMeta.AD
annotations, please refer to the bndtools documentation. -
To use the
Meta.OCD
andMeta.AD
annotations in your modules, you must specify a dependency on the bnd library. We recommend using bnd version 3. Here’s an example of how to include this dependency in a Gradle project:dependencies { compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0" }
When you register a configuration interface, a UI is auto-generated for it in System Settings → Platform → Third Party. That’s the default location; read the next section to learn how to move it somewhere more intuitive.