-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
285 lines (252 loc) · 11.2 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
285 lines (252 loc) · 11.2 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import java.time.Duration
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
// reads properties from gradle.properties file
fun properties(key: String) = project.findProperty(key).toString()
plugins {
id("org.jetbrains.changelog") version "2.2.0"
id("org.jetbrains.intellij.platform") version "2.5.0"
id("org.jetbrains.kotlin.jvm") version "2.1.21"
id("org.jetbrains.kotlinx.kover") version "0.9.4"
id("com.diffplug.spotless") version "8.2.1"
id("org.jlleitschuh.gradle.ktlint") version "14.0.1"
id("pl.allegro.tech.build.axion-release") version "1.21.1"
}
// Configure axion-release BEFORE reading the version
scmVersion {
// Use simple version without branch name suffix
versionCreator("simple")
// Include first 30 chars of branch name for snapshots (keeps version under 64 char limit)
snapshotCreator({ version, position ->
val branch = position.branch.take(30)
"$version-$branch-SNAPSHOT"
})
}
version = scmVersion.version
group = properties("pluginGroup")
description = properties("pluginName")
val jdk = "21"
repositories {
mavenCentral()
mavenLocal()
intellijPlatform { defaultRepositories() }
maven { url = uri("https://www.jetbrains.com/intellij-repository/releases") }
maven { url = uri("https://cache-redirector.jetbrains.com/intellij-dependencies") }
}
configurations.all {
resolutionStrategy.force(
"com.fasterxml.jackson.core:jackson-core:2.21.5",
// jackson-databind resolves to a vulnerable version via the IntelliJ test-framework.
// 2.21.5 clears CVE-2026-54512/54513/54515 on the 2.21 line (patch-level, no API changes).
"com.fasterxml.jackson.core:jackson-databind:2.21.5",
// logback-core resolves to a vulnerable version via ktlint-cli -> logback-classic.
// 1.5.36 fixes the Expression Injection vulnerability (IDE-2384).
"ch.qos.logback:logback-core:1.5.36",
)
}
dependencies {
intellijPlatform {
intellijIdeaCommunity(properties("platformVersion"))
bundledPlugin("com.intellij.java")
plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
testFramework(TestFrameworkType.Platform)
}
implementation(platform("com.fasterxml.jackson:jackson-bom:2.21.5"))
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
implementation(platform("com.squareup.retrofit2:retrofit-bom:2.11.0"))
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:0.23.1")
implementation("org.commonmark:commonmark:0.21.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("io.sentry:sentry:6.27.0")
implementation("javax.xml.bind:jaxb-api:2.3.1") // necessary because since JDK 9 not included
implementation("com.squareup.retrofit2:retrofit")
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
implementation("org.json:json:20231013")
implementation("org.slf4j:slf4j-api:2.0.5")
implementation("org.apache.commons:commons-text:1.12.0")
implementation("org.apache.commons:commons-lang3:3.18.0")
testImplementation("com.google.jimfs:jimfs:1.3.0")
testImplementation("com.squareup.okhttp3:mockwebserver")
testImplementation("junit:junit:4.13.2") { exclude(group = "org.hamcrest") }
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("org.opentest4j:opentest4j:1.3.0")
testImplementation("io.mockk:mockk:1.14.7")
testImplementation("org.awaitility:awaitility:4.2.0")
}
// Configure the IntelliJ Platform Gradle Plugin
intellijPlatform {
// Required configuration for IntelliJ Platform dependencies
pluginConfiguration {
id.set(properties("pluginId"))
name.set(properties("pluginName"))
version.set(project.version.toString())
description.set(
"Snyk helps you find, fix and monitor for known vulnerabilities in your dependencies"
)
ideaVersion {
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))
}
}
pluginVerification {
ides {
// this is gonna need `create` instead of `ide` in future platform versions
ide(IntelliJPlatformType.IntellijIdeaCommunity, "2025.2")
// as of 2025.3, there's no community edition anymore
ide(IntelliJPlatformType.IntellijIdeaUltimate, "2025.3")
ide(IntelliJPlatformType.IntellijIdeaUltimate, "2026.1")
ide(IntelliJPlatformType.IntellijIdeaUltimate, "2026.2")
}
freeArgs.set(listOf("-mute", "TemplateWordInPluginId"))
failureLevel.set(
listOf(
VerifyPluginTask.FailureLevel.COMPATIBILITY_PROBLEMS,
VerifyPluginTask.FailureLevel.INVALID_PLUGIN,
VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES,
)
)
}
}
// Configure Spotless (ktfmt) for Kotlin formatting - Google Style (2-space indent)
spotless {
kotlin { ktfmt("0.47").googleStyle() }
kotlinGradle {
target("*.gradle.kts")
ktfmt("0.47").googleStyle()
}
}
// Configure Ktlint: lint only (formatting is handled by Spotless/ktfmt)
// Formatting rules are disabled in .editorconfig to avoid conflicts
ktlint { ignoreFailures.set(false) }
// Configure Kover for code coverage
kover {
// Use JaCoCo as the coverage backend everywhere (CI and in-container dev).
// The native Kover agent conflicts with MockK's ByteBuddy inline instrumentation: both agents
// retransform the same classes, causing "class redefinition failed: attempted to delete a
// method" (UnsupportedOperationException). JaCoCo does not retransform at instrumentation time
// and coexists with ByteBuddy without conflict. Validated: JaCoCo overall coverage = 52.03%
// (vs native Kover 54.26%), well above the 40% gate; CI Test job passes. Using the same backend
// in CI and in-container makes coverage numbers consistent — no flags, no env-conditional logic.
useJacoco("0.8.14")
reports {
total {
xml {
onCheck = true
xmlFile = layout.buildDirectory.file("reports/kover/report.xml")
}
html {
onCheck = false
htmlDir = layout.buildDirectory.dir("reports/kover/html")
}
}
filters {
excludes {
// Exclude generated code and test utilities
classes("**/generated/**", "**/test/**")
}
}
}
}
// Configure gradle-changelog-plugin
changelog {
version.set(project.version.toString())
groups.set(emptyList())
}
tasks {
withType<JavaCompile> {
sourceCompatibility = jdk
targetCompatibility = jdk
}
withType<KotlinCompile> {
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(jdk))
compilerOptions.languageVersion.set(KotlinVersion.KOTLIN_2_1)
}
withType<Test> {
maxHeapSize = "4096m"
// Fresh JVM per test class: contains a cross-class EDT-queue leak that deadlocked the suite
// intermittently (IDE-2237). Do not remove without a replacement. See the PR / commit / ticket.
forkEvery = 1
testLogging { exceptionFormat = TestExceptionFormat.FULL }
// Preload the ByteBuddy agent at test-JVM startup so MockK never needs runtime self-attach.
// This is unconditional and harmless under the JaCoCo backend (JaCoCo uses class-file
// transformation at load time, not retransformation, so it does not conflict with ByteBuddy).
// In the Docker Desktop LinuxKit VM, HotSpot dynamic attach is non-functional; preloading the
// agent (which MockK would otherwise install via self-attach) makes final-class mocking and
// mockkStatic work in-container without any flag. Uses jvmArgumentProviders (not jvmArgs) for
// lazy/execution-time resolution of the classpath (resolved at execution time, not at
// configuration time, avoiding configuration-phase failures). Sources the jar dynamically from
// the resolved test classpath so the version tracks MockK bumps automatically
// (byte-buddy-agent is transitive via mockk-agent-jvm).
val testClasspath = classpath
jvmArgumentProviders.add(
CommandLineArgumentProvider {
val classpathFiles = testClasspath.files
val hasMockk = classpathFiles.any { it.name.startsWith("mockk-") }
// Only enforce the byte-buddy-agent requirement when MockK is on the classpath:
// withType<Test> applies to all Test-typed tasks (including future tasks such as
// testIdeUi) whose classpath may not include MockK or byte-buddy-agent at all.
// When MockK is absent the agent is not needed; return an empty list so such tasks
// are unaffected. When MockK IS present, a missing or duplicate byte-buddy-agent
// indicates a real dependency regression and we fail loudly.
if (!hasMockk) {
return@CommandLineArgumentProvider emptyList()
}
val agentJars = classpathFiles.filter { it.name.startsWith("byte-buddy-agent-") }
if (agentJars.size != 1) {
throw GradleException(
"Expected exactly one byte-buddy-agent-*.jar on the test classpath " +
"but found ${agentJars.size}: ${agentJars.map { it.name }}. " +
"Check if io.mockk:mockk-agent-jvm still pulls in net.bytebuddy:byte-buddy-agent."
)
}
listOf("-javaagent:${agentJars.single().absolutePath}")
}
)
}
// Wall-clock cap on the unit-test task only (deliberately NOT withType<Test> above, so heavier
// Test tasks such as a future testIdeUi don't inherit this limit). Bounds an *interruptible*
// hung test with a precise "test timed out" failure; the GitHub Actions job `timeout-minutes`
// (in .github/workflows/build.yml) is the real backstop for non-interruptible hangs.
named<Test>("test") { timeout.set(Duration.ofMinutes(25)) }
// Configure the PatchPluginXml task
patchPluginXml {
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))
val content = File("$projectDir/README.md").readText()
val startIndex = content.indexOf("# JetBrains plugin")
val descriptionFromReadme =
content.substring(startIndex).lines().joinToString("\n").run { markdownToHTML(this) }
pluginDescription.set(descriptionFromReadme)
// Get the latest available change notes from the changelog file
changeNotes.set(
"<a href=\"https://github.com/snyk/snyk-intellij-plugin/releases\">Release Notes</a>"
)
}
val createOpenApiSourceJar by
registering(Jar::class) {
// Java sources
from(sourceSets.main.get().java) { include("**/*.java") }
// Kotlin sources
from(kotlin.sourceSets.main.get().kotlin) { include("**/*.kt") }
destinationDirectory.set(layout.buildDirectory.dir("libs"))
archiveClassifier.set("src")
}
buildPlugin {
dependsOn(createOpenApiSourceJar)
from(createOpenApiSourceJar) { into("lib/src") }
}
verifyPlugin { mustRunAfter(patchPluginXml) }
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
channels.set(
listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())
)
}
}