-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
192 lines (155 loc) · 5.49 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
192 lines (155 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import java.time.Instant
buildscript {
dependencies {
constraints {
classpath(libs.commons.io)
classpath(libs.plexus.utils)
classpath(libs.log4j.api)
classpath(libs.log4j.core)
}
}
}
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.shadow)
id("antlr")
id("jacoco")
alias(libs.plugins.jmh)
}
group = "xyz.surendrajat"
version = "1.5.0"
repositories {
mavenCentral()
}
dependencies {
// ANTLR for parsing
antlr(libs.antlr.tool)
implementation(libs.antlr.runtime)
// LSP4J for language server
implementation(libs.lsp4j)
// Kotlin coroutines for concurrency
implementation(libs.kotlinx.coroutines.core)
// JSON for CLI mode
implementation(libs.gson)
// MCP (Model Context Protocol) server
implementation(libs.mcp.kotlin.sdk.server)
// Logging
implementation(libs.slf4j.api)
implementation(libs.logback.classic)
// Testing
testImplementation(libs.junit.jupiter)
testImplementation("org.jetbrains.kotlin:kotlin-test")
// JMH Benchmarking
jmh(libs.jmh.core)
jmh(libs.jmh.generator.annprocess)
}
// Configure ANTLR
tasks.generateGrammarSource {
maxHeapSize = "128m"
arguments = arguments + listOf("-visitor", "-long-messages", "-package", "xyz.surendrajat.smalilsp.parser.generated")
outputDirectory = file("build/generated-src/antlr/main/xyz/surendrajat/smalilsp/parser/generated")
}
// Make Kotlin compilation depend on ANTLR generation
tasks.compileKotlin {
dependsOn(tasks.generateGrammarSource)
}
tasks.compileTestKotlin {
dependsOn(tasks.generateTestGrammarSource)
}
// Fix JMH task dependencies
tasks.named("compileJmhKotlin") {
dependsOn(tasks.named("generateJmhGrammarSource"))
}
tasks.test {
useJUnitPlatform()
// Show test output
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = true
}
// Each test worker needs enough heap for large APK tests (indexing 4K+ files)
maxHeapSize = "1g"
// Limit parallelism: each worker holds a parsed APK in memory.
// Too many forks OOM; too few wastes time. 4 is a safe default.
maxParallelForks = minOf(4, Runtime.getRuntime().availableProcessors())
// Fail on first test failure
failFast = true
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
html.required.set(true)
}
}
// Generate version metadata resource from project version + git commit
val versionPropertiesDir = layout.buildDirectory.dir("generated-resources/version")
val versionPropertiesFile = versionPropertiesDir.map { it.file("version.properties") }
val gitCommitProvider = providers.exec {
commandLine("git", "rev-parse", "--short", "HEAD")
isIgnoreExitValue = true
}.standardOutput.asText.map { it.trim().ifEmpty { "unknown" } }
tasks.register("generateVersionProperties") {
inputs.property("projectVersion", project.version.toString())
inputs.property("gitCommit", gitCommitProvider)
outputs.file(versionPropertiesFile)
doLast {
val commitHash = try {
gitCommitProvider.get()
} catch (_: Exception) {
"unknown"
}
val buildTime = Instant.now().toString()
val file = versionPropertiesFile.get().asFile
file.parentFile.mkdirs()
file.writeText("""version=${project.version}
commit=$commitHash
buildTime=$buildTime
""")
}
}
tasks.processResources {
dependsOn("generateVersionProperties")
from(versionPropertiesDir)
}
// The plain jar (classes-only, no deps) is useless — only the shadow fat jar is distributed.
tasks.jar {
enabled = false
}
tasks.shadowJar {
archiveBaseName.set("smali-lsp")
archiveClassifier.set("")
archiveVersion.set(project.version.toString())
manifest {
attributes["Main-Class"] = "xyz.surendrajat.smalilsp.MainKt"
}
// --- Exclude build-time-only ANTLR4 tool classes ---
// antlr("org.antlr:antlr4:4.13.1") leaks into runtimeClasspath via the ANTLR plugin.
// Only antlr4-runtime (org/antlr/v4/runtime/**) is needed at runtime.
// The tool packages below are used only during grammar code generation at build time.
exclude("org/antlr/v4/Tool*.class") // top-level Tool class
exclude("org/antlr/v4/tool/**")
exclude("org/antlr/v4/codegen/**")
exclude("org/antlr/v4/analysis/**")
exclude("org/antlr/v4/automata/**")
exclude("org/antlr/v4/gui/**")
exclude("org/antlr/v4/semantics/**")
exclude("org/antlr/v4/parse/**")
exclude("org/antlr/v4/misc/**") // tool misc (runtime misc lives under org/antlr/v4/runtime/misc)
// ANTLR3 runtime — transitive dep of the full antlr4 tool, not used at runtime
exclude("org/antlr/runtime/**")
// StringTemplate 4 — only used by ANTLR4 code generation, not at runtime
exclude("org/stringtemplate/**")
// Tree layout — only for ANTLR4 GUI visualization
exclude("org/abego/**")
// ICU4J — only used by ANTLR4 tool for unicode property analysis during grammar compilation
exclude("com/ibm/**")
// --- Exclude Ktor HTTP/WebSocket transport ---
// The MCP Kotlin SDK includes Ktor for HTTP+SSE transport.
// We only use StdioServerTransport. Ktor classes are never loaded on the stdio path
// (class loading is lazy; KtorServerKt extension functions are never called).
exclude("io/ktor/**")
exclude("com/typesafe/**") // Typesafe Config, pulled in by Ktor
}
kotlin {
jvmToolchain(17)
}