idea2023开发插件入门
创建工程
通过 idea plugin 来创建工程
修改 开发语言
默认创建的工程是用scala开发的,但是我不会,就会java,所以改成java创建
- build.gradle.kt 为 build.gradle
- settings.gradle.kt 为 settings.gradle
build.gradle修改为以下:
plugins {
id("java")
//id("org.jetbrains.kotlin.jvm") version "1.8.21"
id("org.jetbrains.intellij") version "1.13.3"
}
group = "com.wtf"
version = "1.0-SNAPSHOT"
repositories {
maven { url 'https://maven.aliyun.com/repository/central/'}
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/' }
maven { url 'https://maven.aliyun.com/repository/jcenter/'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin'}
mavenCentral()
}
// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
version.set("2022.2.5")
type.set("IC") // Target IDE Platform
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
sourceCompatibility = "17"
targetCompatibility = "17"
options.compilerArgs += ['-Xlint:unchecked', '-Xlint:deprecation', '-parameters']
}
//以下原始的都不要
/*
tasks {
// Set the JVM compatibility versions
withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
}
*/
/* withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}*//*
patchPluginXml {
sinceBuild.set("222")
untilBuild.set("232.*")
}
*/
/* signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}*//*
}
*/
第一次编译会下载IC-idea,大概 600多M
helloworld插件开发
idea 会创建一个 ShowHello
类
public class ShowHello extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
// TODO: insert action logic here
Messages.showMessageDialog("hello idea plugin","这里标题",Messages.getInformationIcon());
}
}
编译运行
找到 intellij->runIde
运行成功会打开一个新的ide, 随他创建一个工程就行,因为我们创建的菜单在help下,直接在 help 菜单下找就行,效果如下 :
good luck!