ProxyAI/build.gradle.kts
2026-04-23 15:40:20 +01:00

251 lines
7.5 KiB
Kotlin

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.RunIdeTask
import java.io.FileInputStream
import java.util.*
val localPropertiesFile = file("local.properties")
val env = environment("env").getOrNull()
fun loadProperties(filename: String): Properties = Properties().apply {
load(FileInputStream(filename))
}
val localProperties: Properties? = if (localPropertiesFile.exists()) {
loadProperties("local.properties")
} else {
null
}
val customIdePath: String? = localProperties?.getProperty("customIdePath")
fun properties(key: String): Provider<String> {
if ("win-arm64" == env) {
val property = loadProperties("gradle-win-arm64.properties").getProperty(key)
?: return providers.gradleProperty(key)
return providers.provider { property }
}
return providers.gradleProperty(key)
}
fun environment(key: String) = providers.environmentVariable(key)
plugins {
id("proxyai.java-conventions")
id("org.jetbrains.intellij.platform")
alias(libs.plugins.changelog)
alias(libs.plugins.protobuf)
alias(libs.plugins.kotlin.serialization)
}
group = properties("pluginGroup").get()
version = properties("pluginVersion").get() + "-" + properties("pluginSinceBuild").get()
repositories {
mavenCentral()
gradlePluginPortal()
intellijPlatform {
defaultRepositories()
}
}
changelog {
groups.empty()
repositoryUrl.set(properties("pluginRepositoryUrl"))
}
dependencies {
intellijPlatform {
intellijIdea(properties("platformVersion"))
bundledPlugin("com.intellij.java")
bundledPlugin("org.jetbrains.kotlin")
bundledPlugin("Git4Idea")
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.JUnit5)
}
implementation(project(":proxyai-telemetry"))
implementation(project(":proxyai-treesitter"))
implementation(platform(libs.slf4j.bom))
implementation(platform(libs.jackson.bom))
implementation(platform(libs.mcp.sdk.bom))
implementation(libs.jackson.datatype.jdk8)
implementation(libs.jackson.datatype.jsr310)
implementation(libs.jackson.module.kotlin)
implementation(libs.kotlin.stdlib)
implementation(libs.acp.sdk) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core-jvm")
}
implementation(libs.flexmark.all) {
// vulnerable transitive dependency
exclude(group = "org.jsoup", module = "jsoup")
}
implementation(libs.koog.agents) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-common")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-jdk8")
}
implementation(libs.koog.serialization.jackson)
implementation(libs.jsoup)
implementation(libs.commons.text)
implementation(libs.jtokkit)
implementation(libs.grpc.protobuf)
implementation(libs.grpc.stub)
implementation(libs.grpc.netty.shaded)
implementation(libs.protobuf.runtime)
implementation(libs.mcp.sdk)
testImplementation(libs.junit4)
testImplementation(kotlin("test"))
}
tasks.register<Exec>("updateSubmodules") {
workingDir(rootDir)
commandLine("git", "submodule", "update", "--init", "--recursive")
}
intellijPlatform {
pluginConfiguration {
name = properties("pluginName")
version = properties("pluginVersion").get() + "-" + properties("pluginSinceBuild").get()
description =
providers.fileContents(layout.projectDirectory.file("DESCRIPTION.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in DESCRIPTION.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n")
.let(::markdownToHTML)
}
}
val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
changeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
ideaVersion {
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
}
}
pluginVerification {
ides {
recommended()
}
}
signing {
certificateChain = System.getenv("CERTIFICATE_CHAIN")
privateKey = System.getenv("PRIVATE_KEY")
password = System.getenv("PRIVATE_KEY_PASSWORD")
}
publishing {
token = System.getenv("PUBLISH_TOKEN")
channels = listOf("stable")
}
}
/**
- * Task to run a custom IntelliJ IDEA sandbox.
- *
- * This task launches a custom IntelliJ IDEA installation using the path specified in the
- * 'customIdePath' property from local.properties.
- *
- * IMPORTANT:
- * - On macOS, the path must include the 'Contents' directory (e.g., /Applications/IntelliJ IDEA.app/Contents).
- * - For Windows or Linux, specify the appropriate path to the IntelliJ IDEA installation.
- *
- * Usage:
- * ./gradlew runCustomIde
- */
if (customIdePath != null) {
tasks.register<RunIdeTask>("runCustomIde") {
group = "intellij"
description = "Start custom idea sandbox"
sandboxDirectory = file(customIdePath)
environment("ENVIRONMENT", "LOCAL")
}
}
tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
}
prepareSandbox {
dependsOn("updateSubmodules")
from(layout.projectDirectory.dir("src/main/cpp/llama.cpp")) {
into("ProxyAI/llama.cpp")
}
}
runIde {
environment("ENVIRONMENT", "LOCAL")
}
buildPlugin {
dependsOn("prepareSandbox")
}
publishPlugin {
dependsOn("patchChangelog")
}
test {
exclude("**/testsupport/*")
testLogging {
events("started", "passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
}
}
}
protobuf {
protoc {
artifact = libs.protobuf.protoc.get().toString()
}
plugins {
create("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${libs.versions.grpc.get()}"
}
}
generateProtoTasks {
all()
.forEach {
it.plugins {
create("grpc")
}
}
}
}