build.gradle.kts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. plugins {
  2. id("java")
  3. id("org.jetbrains.intellij.platform") version "2.2.1"
  4. kotlin("jvm") version "1.9.23"
  5. }
  6. group = "paviko.opencode"
  7. version = "26.2.8"
  8. val guiOnly = project.findProperty("guiOnly")?.toString()?.toBoolean() ?: false
  9. val webguiDist = project.findProperty("webguiDist")?.toString()
  10. repositories {
  11. mavenCentral()
  12. intellijPlatform {
  13. defaultRepositories()
  14. }
  15. }
  16. java {
  17. // Align with IntelliJ Platform 2024.3+ requirement
  18. sourceCompatibility = JavaVersion.VERSION_21
  19. targetCompatibility = JavaVersion.VERSION_21
  20. }
  21. kotlin {
  22. jvmToolchain(21)
  23. }
  24. sourceSets {
  25. test {
  26. kotlin {
  27. srcDir("src/test/kotlin")
  28. }
  29. }
  30. // Create a separate source set for unit tests that don't need IntelliJ
  31. create("unitTest") {
  32. kotlin {
  33. srcDir("src/unitTest/kotlin")
  34. }
  35. resources {
  36. srcDir("src/unitTest/resources")
  37. }
  38. compileClasspath += sourceSets.main.get().output
  39. runtimeClasspath += output + compileClasspath
  40. }
  41. }
  42. dependencies {
  43. implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1")
  44. // IntelliJ Platform dependencies
  45. intellijPlatform {
  46. intellijIdeaCommunity("2024.3")
  47. bundledPlugin("com.intellij.java")
  48. bundledPlugin("org.jetbrains.plugins.terminal")
  49. pluginVerifier()
  50. zipSigner()
  51. }
  52. testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
  53. testImplementation("org.mockito:mockito-core:5.5.0")
  54. testImplementation("org.mockito:mockito-inline:5.2.0")
  55. testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0")
  56. testImplementation(kotlin("test"))
  57. testRuntimeOnly("org.junit.platform:junit-platform-launcher")
  58. // Unit test dependencies (no IntelliJ, no JUnit)
  59. "unitTestImplementation"("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1")
  60. "unitTestImplementation"(kotlin("stdlib"))
  61. }
  62. intellijPlatform {
  63. pluginConfiguration {
  64. ideaVersion {
  65. sinceBuild.set("243")
  66. }
  67. // Provide metadata without setting an upper build bound (no untilBuild)
  68. description = providers.provider {
  69. val f = file("description.html")
  70. if (!f.isFile) {
  71. return@provider "Runs local OpenCode backend and displays the chat UI."
  72. }
  73. val text = f.readText().trim()
  74. if (text.isEmpty()) {
  75. "Runs local OpenCode backend and displays the chat UI."
  76. } else {
  77. text
  78. }
  79. }
  80. changeNotes = providers.provider {
  81. val f = file("changelog.html")
  82. if (!f.isFile) {
  83. return@provider "See CHANGELOG.md for details."
  84. }
  85. val text = f.readText().trim()
  86. if (text.isEmpty()) {
  87. "See CHANGELOG.md for details."
  88. } else {
  89. text
  90. }
  91. }
  92. }
  93. }
  94. tasks {
  95. processResources {
  96. val minVersion = project.findProperty("opencode.min.version")?.toString() ?: "1.1.1"
  97. inputs.property("opencodeMinVersion", minVersion)
  98. filesMatching("opencode-build.properties") {
  99. expand("opencodeMinVersion" to minVersion)
  100. }
  101. if (guiOnly) {
  102. // Exclude bundled binaries for gui-only variant
  103. exclude("bin/**")
  104. }
  105. }
  106. // Copy webgui-dist into resources and generate file-list.txt for gui-only variant
  107. if (guiOnly) {
  108. val copyWebgui = register<Copy>("copyWebguiDist") {
  109. val srcDir = if (webguiDist != null) file(webguiDist!!) else rootProject.rootDir.resolve("packages/opencode/webgui-dist")
  110. from(srcDir)
  111. into(layout.buildDirectory.dir("resources/main/webgui-app"))
  112. }
  113. val generateFileList = register("generateWebguiFileList") {
  114. dependsOn(copyWebgui)
  115. doLast {
  116. val webguiDir = layout.buildDirectory.dir("resources/main/webgui-app").get().asFile
  117. val files = webguiDir.walkTopDown()
  118. .filter { it.isFile && it.name != "file-list.txt" }
  119. .map { it.relativeTo(webguiDir).invariantSeparatorsPath }
  120. .sorted()
  121. .toList()
  122. File(webguiDir, "file-list.txt").writeText(files.joinToString("\n") + "\n")
  123. logger.lifecycle("Generated webgui-app/file-list.txt with ${files.size} entries")
  124. }
  125. }
  126. named("processResources") {
  127. dependsOn(generateFileList)
  128. }
  129. }
  130. // Ensure no upper build bound is set in plugin.xml so the plugin stays compatible with newer IDEs
  131. patchPluginXml {
  132. // keep sinceBuild from pluginConfiguration, but expand upper bound to newer IDE builds
  133. untilBuild.set("261.*")
  134. if (guiOnly) {
  135. pluginId.set("paviko.opencode-ux-plus-gui-only")
  136. pluginName.set("OpenCode UX+ GUI Only (unofficial)")
  137. }
  138. }
  139. prepareSandbox {
  140. from(rootProject.rootDir.resolve("LICENSE")) {
  141. into("${intellijPlatform.projectName.get()}")
  142. }
  143. }
  144. // Rename output archive for gui-only variant
  145. if (guiOnly) {
  146. named<Zip>("buildPlugin") {
  147. archiveBaseName.set("opencode-plugin-gui-only")
  148. }
  149. }
  150. // Configure test task for IntelliJ integration tests
  151. test {
  152. useJUnitPlatform()
  153. systemProperty("java.awt.headless", "true")
  154. systemProperty("idea.test.cyclic.buffer.size", "1048576")
  155. systemProperty("idea.home.path", "")
  156. jvmArgs(
  157. "-Djava.awt.headless=true",
  158. "--add-opens=java.base/java.lang=ALL-UNNAMED",
  159. "--add-opens=java.base/java.util=ALL-UNNAMED"
  160. )
  161. }
  162. // Create unit test task that runs without IntelliJ dependencies
  163. register<JavaExec>("unitTest") {
  164. dependsOn("compileUnitTestKotlin")
  165. mainClass.set("paviko.opencode.ui.StandaloneMessageTestKt")
  166. classpath = sourceSets["unitTest"].runtimeClasspath
  167. systemProperty("java.awt.headless", "true")
  168. jvmArgs(
  169. "-Djava.awt.headless=true",
  170. "--add-opens=java.base/java.lang=ALL-UNNAMED",
  171. "--add-opens=java.base/java.util=ALL-UNNAMED"
  172. )
  173. }
  174. // Make build depend on unit tests
  175. build {
  176. dependsOn("unitTest")
  177. }
  178. }