What is a Plugin?
A plugin is a standalone module that extends Halo’s capabilities by:- Adding custom content types (Extensions)
- Creating custom API endpoints
- Handling events and implementing business logic
- Providing UI components and static resources
- Integrating with external services
Core Concepts
BasePlugin
Every plugin must extend theBasePlugin class, which serves as the entry point for your plugin:
PluginContext
ThePluginContext provides information about your plugin and facilitates communication with the application:
PF4J recommends using
PluginContext instead of PluginWrapper for better encapsulation.Plugin Metadata
Plugins are defined using the@GVK annotation and YAML descriptors.
The @GVK Annotation
Extensions and custom resources use the@GVK annotation to define their metadata:
group: The API group (e.g.,plugin.halo.run,my-plugin.example.com)version: API version (e.g.,v1alpha1,v1beta1,v1)kind: The resource type name (e.g.,Plugin,Post,Comment)plural: Plural form for API endpoints (e.g.,plugins,posts)singular: Singular form for display (e.g.,plugin,post)
GroupVersionKind (GVK)
The GVK uniquely identifies an Extension type:Extension Interface
TheExtension interface is the foundation for all custom resources in Halo:
AbstractExtension
Most Extensions extendAbstractExtension for convenience:
Creating Your First Plugin
package com.example.myplugin;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import run.halo.app.plugin.BasePlugin;
import run.halo.app.plugin.PluginContext;
@Slf4j
@Component
public class MyPlugin extends BasePlugin {
public MyPlugin(PluginContext pluginContext) {
super(pluginContext);
}
}
apiVersion: plugin.halo.run/v1alpha1
kind: Plugin
metadata:
name: my-plugin
spec:
version: 1.0.0
requires: ">=2.0.0"
author:
name: Your Name
website: https://example.com
logo: https://example.com/logo.png
homepage: https://github.com/yourusername/my-plugin
displayName: My Awesome Plugin
description: A plugin that does amazing things
license:
- name: MIT
url: https://opensource.org/licenses/MIT
Plugin Descriptor Fields
Theplugin.yaml file defines your plugin’s metadata:
| Field | Type | Required | Description |
|---|---|---|---|
apiVersion | String | Yes | Always plugin.halo.run/v1alpha1 |
kind | String | Yes | Always Plugin |
metadata.name | String | Yes | Unique plugin identifier |
spec.version | String | Yes | Semantic version |
spec.requires | String | No | Halo version requirement (default: *) |
spec.author.name | String | Yes | Author name |
spec.author.website | String | No | Author website |
spec.logo | String | No | Plugin logo URL |
spec.homepage | String | No | Plugin homepage |
spec.repo | String | No | Source repository URL |
spec.displayName | String | No | Display name for UI |
spec.description | String | No | Plugin description |
spec.license | Array | No | License information |
spec.pluginDependencies | Map | No | Other plugin dependencies |
Development vs Production
ThePluginContext provides the runtime mode:
Best Practices
Next Steps
- Learn about plugin project structure
- Understand the plugin lifecycle
- Create custom extensions and APIs
- Add custom endpoints