Mastering IntelliJ IDEA Plugin Development: A Step‑by‑Step Guide
This article introduces the fundamentals of IntelliJ IDEA plugin development, covering plugin types, project structure, essential components, a complete development workflow with Gradle, action registration, extension points, live templates, Dubbo integration, publishing procedures, common pitfalls, and how to include local JARs.
Concept Overview
IntelliJ IDEA is a essential IDE for Java developers, and its plugin ecosystem greatly extends its functionality and improves developer efficiency.
Plugin Types
Custom language support (e.g., Go), providing file type recognition, formatting, and compilation.
Framework support (e.g., Spring), offering special code recognition and framework‑specific features.
Tool integration (e.g., cloud services), adding UI elements and external resource access.
UI augmentation, limited to UI modifications.
Development Directory Structure
Core Components
Configuration file (META-INF/plugin.xml) describing the plugin.
ClassLoader – each plugin has an isolated ClassLoader.
Component – three levels: Application, Project, Module, configured in plugin.xml.
Extensions and Extension Points – extend IDEA or provide points for other plugins.
Action – defined in plugin.xml and triggered from the UI.
Icon – icons used by the plugin.
Service – backend services used by the plugin.
Dependencies – other plugins or third‑party libraries.
Development Process Overview
1 Create Project
Use the Gradle‑based "IntelliJ Platform Plugin" project type, which simplifies adding third‑party dependencies and is the officially recommended approach.
2 Set Entry Point
Add an Action entry in plugin.xml to create a UI entry point.
<actions>
<!-- Add your actions here -->
<group id="groupId" text="Display Text 1" description="Tooltip text">
<add-to-group group-id="MainMenu" anchor="last"/>
<action class="com.example.MyAction" id="myAction" text="Display Text 2" description="Tooltip text"/>
</group>
</actions>3 Write Action Logic
Implement the action class referenced in plugin.xml and add the required processing logic.
4 Use Extension Points
Declare custom extension points in plugin.xml and implement them.
<extensions defaultExtensionNs="com.intellij">
<!-- Add custom extension tags -->
<customJavadocTagProvider implementation="com.example.MyTagProvider"/>
</extensions>5 Custom LiveTemplate
Configure a live template provider and context in plugin.xml and supply template files.
<!-- Custom LiveTemplate -->
<defaultLiveTemplatesProvider implementation="com.example.MyTemplatesProvider"/>
<liveTemplateContext implementation="com.example.MyTemplateContext"/>Implementation example:
@Override
public String[] getDefaultLiveTemplateFiles() {
return new String[]{"liveTemplates/template1", "liveTemplates/template2"};
}6 Invoke Dubbo from the Plugin
Add Dubbo dependencies in build.gradle and use the generic service API.
compile 'org.apache.dubbo:dubbo:2.7.7'
compile 'org.apache.dubbo:dubbo-dependencies-zookeeper:2.7.7'
ClassLoader backCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
ApplicationConfig application = new ApplicationConfig();
application.setName("appName");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("zookeeper://127.0.0.1:2181");
ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
reference.setApplication(application);
reference.setRegistry(registry);
reference.setInterface("com.example.Service");
reference.setVersion("1.0");
reference.setGeneric(true);
GenericService genericService = reference.get();
Object result = genericService.$invoke("methodName", new String[]{"java.lang.String"}, new Object[]{"param"});
System.out.println(result);
Thread.currentThread().setContextClassLoader(backCl);7 Publish Plugin to an IDEA Repository
Configure publishing in build.gradle and run the publishPlugin task.
publishPlugin {
host = 'https://your-repo.com'
username = 'yourUser'
password = 'yourPassword'
token = 'yourToken'
}If the upload fails with an "Accept header" error, downgrade the org.jetbrains.intellij plugin version to 2.x or implement a custom upload method without the Accept header.
8 Add Local JAR Dependencies
Include local JARs via Gradle:
compile fileTree(dir: 'src/main/resources/lib', includes: ['*jar'])Place the JAR files in the specified directory.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
