import org.jetbrains.intellij.platform.gradle.TestFrameworkType plugins { id("org.jetbrains.kotlin.jvm") id("org.jetbrains.changelog") id("org.jetbrains.intellij.platform") id("org.jetbrains.intellij.platform.grammarkit") } // Grammar-Kit output. Committed so diffs are reviewable, never hand-edited. val generatedSourceDir = file("src/main/gen") sourceSets { main { java.srcDirs(generatedSourceDir) } } // Read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html dependencies { testImplementation(libs.junit) // IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html intellijPlatform { intellijIdea("2025.3.5") testFramework(TestFrameworkType.Platform) // Add plugin dependencies for compilation here, for example: // bundledPlugin("com.intellij.java") } } // purgeOldFiles is not enough: Grammar-Kit rewrites only the files whose rule // changed, so a PSI interface can keep an accessor its regenerated Impl no longer has // (`JaiDeclaration.getArgumentList()` with no override) and the build then fails // inside generated code. Wiping first makes every generation self-consistent. // // This is a separate Delete task rather than a doFirst, because any lambda added to a // task from a Kotlin build script captures the script object, which the configuration // cache cannot serialize. val cleanGeneratedSources by tasks.registering(Delete::class) { delete(generatedSourceDir) } tasks.generateParser { dependsOn(cleanGeneratedSources) sourceFile.set(file("src/main/grammar/Jai.bnf")) targetRootOutputDir.set(generatedSourceDir) pathToParser.set("dev/hgh/jai/parser/JaiParser.java") pathToPsiRoot.set("dev/hgh/jai/psi") purgeOldFiles.set(true) } // Without this the compile tasks read src/main/gen with no ordering guarantee, so an // edit to Jai.bnf could be compiled against the *previous* generated parser and the // tests would quietly assert the old grammar. Editing Jai.bnf must be enough. tasks.compileJava { dependsOn(tasks.generateParser) } tasks.compileKotlin { dependsOn(tasks.generateParser) } // Forward -Djai.debug.* to the test JVM for the scratch parser harness. tasks.test { System.getProperties().forEach { key, value -> val name = key.toString() if (name.startsWith("jai.debug.")) systemProperty(name, value.toString()) } }