跳到主内容
Kotlin
文章阅读

idea 插件开发之使用 Jewel (idea 风格的Compose)

2025/12/16253 次阅读6 分钟

添加plugins + dependencies


plugins {
    id("org.jetbrains.compose") version "1.8.2"
    id("org.jetbrains.kotlin.plugin.compose") version "2.1.20"
}


dependencies {
    implementation("org.smartboot.socket:aio-pro:latest.release")
    testImplementation("junit:junit:latest.release")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:latest.release")

    intellijPlatform {
        when (ideType) {
            "252" -> {
                intellijIdea("2025.2")
            }

            "251" -> {
//                intellijIdeaCommunity("2025.1.4.1")
                local("/Applications/Android Studio.app")
            }
        }
        bundledPlugins(bPlugins)
        //"io.flutter:87.1"
        plugins("Dart:$dartVersion", "io.flutter:87.1")
        pluginVerifier()
        zipSigner()
        javaCompiler()

        bundledModule("intellij.libraries.ktor.client")
        bundledModule("intellij.libraries.ktor.client.cio")

        testBundledModules("intellij.libraries.ktor.client", "intellij.libraries.ktor.client.cio")

        testFramework(TestFrameworkType.Platform)



        // jewel
        bundledModule("intellij.platform.jewel.foundation")
        bundledModule("intellij.platform.jewel.ui")
        bundledModule("intellij.platform.jewel.ideLafBridge")
        bundledModule("intellij.platform.jewel.markdown.core")
        bundledModule("intellij.platform.jewel.markdown.ideLafBridgeStyling")
        bundledModule("intellij.libraries.compose.foundation.desktop")
        bundledModule("intellij.libraries.skiko")
    }
    testImplementation("junit:junit:4.13.2")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")

}

plugin.xml


<dependencies>
        <plugin id="com.intellij.modules.platform"/>
        <plugin id="org.jetbrains.plugins.yaml"/>
        <plugin id="Dart"/>
        <plugin id="org.intellij.plugins.markdown"/>
        <plugin id="org.jetbrains.plugins.terminal"/>
        <plugin id="com.intellij.modules.json"/>
        <plugin id="com.intellij.platform.images"/>
        <plugin id="org.intellij.groovy"/>
        <module name="intellij.libraries.ktor.client"/>
        <module name="intellij.libraries.ktor.client.cio"/>
        <module name="intellij.platform.jewel.foundation"/>
        <module name="intellij.platform.jewel.ui"/>
        <module name="intellij.platform.jewel.ideLafBridge"/>
        <module name="intellij.libraries.compose.foundation.desktop"/>
        <module name="intellij.libraries.skiko"/>
        <module name="intellij.platform.jewel.markdown.core"/>
        <module name="intellij.platform.jewel.markdown.ideLafBridgeStyling"/>
    </dependencies>

在 toolWindows里面使用

关键函数: toolWindow.addComposeTab


class DartVmServiceWindowsFactory : ToolWindowFactory {
    override fun createToolWindowContent(
        project: Project,
        toolWindow: ToolWindow
    ) {
        toolWindow.addComposeTab("Vm") {
            DartVmStatusComponent(project)
        }
        toolWindow.addComposeTab("Http Monitor") {
            DartHttpUI(project)
        }
        toolWindow.addComposeTab("Logging") {
            DartVmLoggingComponent(project)
        }
        toolWindow.addComposeTab("Provider") {
            ProviderComposeComponent(project)
        }

        if (System.getenv("DEV") == "true") {
            toolWindow.addComposeTab("Demo") {
                JsonViewerDemo()
            }

            toolWindow.addComposeTab("常见依赖") {
                AddPackageDialog(project) {}
            }
        }

    }

    override fun shouldBeAvailable(project: Project): Boolean {
        return PluginConfig.getInstance(project).state.enableVmServiceToolWindow
    }


}

使用jewel panel


@Composable
fun Panel(){
    JewelComposePanel { 
        // todo 
    }
}
返回顶部