plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.9.23" id("org.jetbrains.intellij") version "1.17.3" id("org.jetbrains.grammarkit") version "2022.3.2.2" id("de.undercouch.download") version "5.6.0" } val slintVersion: String by project //github url val slintGithubUrl = "https://github.com/slint-ui/slint/releases/download/v$slintVersion" //download dir val slintViewerDownloadDir = "${layout.buildDirectory.get()}/slint-lsp" //decompression path val slintViewerBinaryDir = "${layout.buildDirectory.get()}/slint-lsp/$slintVersion" val grammarGeneratedRoot = "${layout.buildDirectory.get()}/generated/sources/grammar/" //github filename-> decompression name val slintViewerFilenames = arrayOf( "slint-lsp-linux.tar.gz" to "slint-lsp-linux", "slint-lsp-macos.tar.gz" to "slint-lsp-macos", "slint-lsp-windows.zip" to "slint-lsp-windows.exe", ) sourceSets { main { java { srcDirs(file("${grammarGeneratedRoot}/main/java")) } } } group = "me.zhouxi" version = "0.0.1" repositories { mavenCentral() } intellij { version.set("IU-2024.1") sandboxDir.set("idea-sandbox") plugins.set(listOf("java")) } dependencies { } tasks { buildPlugin { //copy slint-lsp to plugin dir from(slintViewerBinaryDir) { into("/slint-lsp") } } withType().configureEach { if (name.endsWith("main()")) { notCompatibleWithConfigurationCache("JavaExec created by IntelliJ") } } runIde { //copy slint-lsp doFirst { copy { from(slintViewerBinaryDir) into("idea-sandbox/plugins/intellij-slint/slint-lsp") } } } withType { sourceCompatibility = "17" targetCompatibility = "17" } withType { kotlinOptions.jvmTarget = "17" } patchPluginXml { sinceBuild.set("232") untilBuild.set("242.*") } generateParser { purgeOldFiles.set(true) sourceFile.set(file("src/main/grammar/main.bnf")) pathToParser.set("SlintParser") targetRootOutputDir.set(file("${grammarGeneratedRoot}/main/java")) pathToPsiRoot.set("psi") } generateLexer { sourceFile.set(file("src/main/grammar/main.flex")) targetOutputDir.set(file("${grammarGeneratedRoot}/main/java/me/zhouxi/slint/lang/lexer")) purgeOldFiles.set(true) } withType { jvmArgs("-Djava.awt.headless=true") } register("downloadSlintResource") { doFirst { slintViewerFilenames.forEach { fileDesc -> val (filename, renamed) = fileDesc val src = "$slintGithubUrl/$filename" val fileTarget = "$slintViewerDownloadDir/$filename" download.run { src(src) dest(fileTarget) } copy { val fileTree = if (filename.endsWith("zip")) { zipTree(fileTarget) } else { tarTree(fileTarget) } from(fileTree) //include executable file path include("slint-lsp/slint-lsp*") eachFile { //rename to platform name this.relativePath = RelativePath(true, renamed) } into(slintViewerBinaryDir) } } } } 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")) } }