-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
470 lines (400 loc) · 17.8 KB
/
build.gradle.kts
File metadata and controls
470 lines (400 loc) · 17.8 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
import com.virtuslab.gitmachete.buildsrc.*
import com.virtuslab.gitmachete.buildsrc.AnyVersion.Companion.productCode
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.changelog.Changelog
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.BuildPluginTask
import org.jetbrains.intellij.platform.gradle.tasks.SignPluginTask
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
import java.util.Base64
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion as GradleKotlinVersion
plugins {
checkstyle
`java-library`
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.jetbrains.intellij)
alias(libs.plugins.taskTree)
}
val javaVersionProperties = PropertiesHelper.getProperties(rootDir.resolve("java-version.properties"))
val targetJavaVersion: JavaVersion by extra(
JavaVersion.toVersion(javaVersionProperties.getProperty("jdkVersionForGeneratedClassfiles").toInt()),
)
val ciBranch: String? by extra(System.getenv("CIRCLE_BRANCH"))
val isCI: Boolean by extra(System.getenv("CI") == "true")
val jetbrainsMarketplaceToken: String? by extra(System.getenv("JETBRAINS_MARKETPLACE_TOKEN"))
val intellijVersions by extra(
IntellijVersions.from(
intellijVersionsProperties = PropertiesHelper.getProperties(rootDir.resolve("intellij-versions.properties")),
overrideBuildTarget = project.properties["overrideBuildTarget"] as String?,
),
)
fun String.fromBase64(): String = String(Base64.getDecoder().decode(this))
val pluginSignCertificateChain: String? by extra(System.getenv("PLUGIN_SIGN_CERT_CHAIN_BASE64")?.fromBase64())
val pluginSignPrivateKey: String? by extra(System.getenv("PLUGIN_SIGN_PRIVATE_KEY_BASE64")?.fromBase64())
val pluginSignPrivateKeyPass: String? by extra(System.getenv("PLUGIN_SIGN_PRIVATE_KEY_PASS"))
val shouldRunAllCheckers: Boolean by extra(isCI || project.hasProperty("runAllCheckers"))
tasks.register<UpdateIntellijVersions>("updateIntellijVersions")
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
apply<JavaLibraryPlugin>()
java {
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion // redundant, added for clarity
}
// String interpolation support, see https://github.com/antkorwin/better-strings.
// This needs to be enabled in each subproject by default because there's going to be no warning
// if this annotation processor isn't run in any subproject (the strings will be just interpreted
// verbatim, without interpolation applied).
// In such case, we'd only capture an unprocessed interpolation in ArchUnit tests by analyzing constant pools of classes.
betterStrings()
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(
listOf(
// Treat each compiler warning (esp. the ones coming from Checker Framework) as an error.
"-Werror",
// Warn of type-unsafe operations on generics.
"-Xlint:unchecked",
),
)
options.isFork = true
// `sourceCompatibility` and `targetCompatibility` say nothing about the Java APIs available to the compiled code.
// In fact, for X < Y it's perfectly possible to compile Java X code that uses Java Y APIs...
// This will work fine, until we actually try to run those compiled classes under Java X-compatible JVM,
// when we'll end up with NoSuchMethodError for APIs added between Java X and Java Y
// (i.e. for X=8 and Y=11: InputStream#readAllBytes, Stream#takeWhile and String#isBlank).
// `options.release = X` makes sure that regardless of Java version used to run the compiler,
// only Java X-compatible APIs are available to the compiled code.
options.release.set(Integer.parseInt(targetJavaVersion.majorVersion))
}
tasks.withType<Javadoc> {
// See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363) for information about the `-Xwerror` option:
// this is needed to make sure that javadoc always fails on warnings
// (esp. important on CI since javadoc there for some reason seems to never raise any errors otherwise).
// The '-quiet' as second argument is actually a hack around
// https://github.com/gradle/gradle/issues/2354:
// since the one-parameter `addStringOption` doesn't seem to work, we need to add an extra
// `-quiet`, which is added anyway by Gradle.
(options as StandardJavadocDocletOptions).addStringOption("Xwerror", "-quiet")
// Suppress `doclint` for `missing`; otherwise javadoc for every member would be required.
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
options.quiet()
}
tasks.withType<Test> {
useJUnitPlatform()
if (project.properties["forceRunTests"] != null) {
outputs.upToDateWhen { false }
}
testLogging {
if (project.properties["printTestOutput"] != null) {
showStandardStreams = true
}
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showExceptions = true
showStackTraces = true
}
}
configureCheckerFramework()
configureCheckstyle()
configureSpotless()
// A few libraries (like JGit) transitively pull in a version of slf4j-api
// that might be different from the slf4j-api version that IntelliJ depends on.
// SLF4J guarantees that the code compiled against a certain slf4j-api version will work with any
// other version of slf4j-api (http://www.slf4j.org/manual.html#compatibility).
// We rely on that guarantee: our plugin effectively uses whatever slf4j-api version is provided by IntelliJ.
// SLF4J does NOT guarantee, however, that slf4j-api version X will work with any slf4j
// implementation version Y for X != Y.
// To avoid a clash between JGit&co.'s slf4j-api and Intellij's slf4j implementation
// (and also between JGit&co.'s slf4j-api and Intellij's slf4j-api), we need to exclude the former
// from ALL dependencies.
configurations.runtimeClasspath { exclude(group = "org.slf4j", module = "slf4j-api") }
tasks.withType<KotlinCompile> {
val kotlinVersionStr = intellijVersions.kotlinVersion.replace("""^(\d+\.\d+).*""".toRegex(), "$1")
val kotlinVersion = GradleKotlinVersion.fromVersion(kotlinVersionStr)
compilerOptions {
apiVersion.set(kotlinVersion)
languageVersion.set(kotlinVersion)
}
}
}
subprojects {
// This is necessary to make sure that `buildPlugin` task puts jars of all relevant subprojects
// into the final zip.
// No need to include near-empty (only with META-INF/MANIFEST.MF) jars
// for subprojects that don't have any production code.
if (sourceSets["main"].allSource.srcDirs.any { it.exists() }) {
rootProject.dependencies { implementation(project) }
}
// By default, the jar name will be formed only from the last segment of subproject path.
// Since these last segments are NOT unique (there are many `api`s and `impl`s),
// the effective jar name will be something like api.jar, api_1.jar, api_2.jar etc.,
// which is suboptimal.
// Let's use full name like frontend-ui-api.jar instead.
base.archivesName.set(path.replaceFirst(":", "").replace(":", "-"))
if (path.startsWith(":frontend:")) {
// We use `.base` rather than `.module` on purpose: `.base` provides exactly what frontend
// subprojects need (the `intellijPlatform { ... }` dependencies/repositories DSL and IJ platform
// jars on the compile classpath via `compileOnly`) without any of the stuff that `.module` adds
// on top - most notably the `composedJar`/`instrumentedJar` tasks, the `-base` archive classifier
// from `JarCompanion`, and (since intellij-platform-gradle-plugin 2.14.0) the auto-inference that
// treats every `ProjectDependency` into a "pure module project" as a `pluginModule(...)` entry and
// packages the resulting jar into `lib/modules/` in the final plugin zip.
// That last behavior is incompatible with our flat (v1) plugin.xml layout: classes under
// `lib/modules/` are not on the plugin's main runtime classpath unless declared as v2
// `<content><module .../></content>`, which we don't use.
apply(plugin = "org.jetbrains.intellij.platform.base")
applyGuiEffectChecker()
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
jetbrainsRuntime()
}
}
dependencies {
intellijPlatform {
intellijIdea(intellijVersions.buildTarget)
bundledPlugin("Git4Idea")
}
}
// The `.base` plugin extends `compileOnly`/`testCompileOnly` from the IJ platform
// configurations, so IJ classes are visible at compile time. It does NOT, however,
// put them on the `testRuntimeClasspath` - the `.module` plugin normally does that
// indirectly by re-registering the `test` task via `TestCompanion`/`TestIdeTask`
// (see `TestIdeTask.configuration` in intellij-platform-gradle-plugin), which
// explicitly sets `classpath = files(..., intellijPlatformTestClasspath, ...)`.
// Since we're not using `.module`, we wire the IJ platform test classpath (a
// resolvable configuration created by `.base`, transitively extending from
// `intellijPlatform`/`intellijPlatformPlugins`/`intellijPlatformBundledPlugins`/
// `intellijPlatformBundledModules`) onto the plain Gradle `test` task ourselves.
tasks.withType<Test>().configureEach {
classpath += configurations["intellijPlatformTestClasspath"]
}
}
}
// Root project config
group = "com.virtuslab"
configureVersionFromGit()
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
jetbrainsRuntime()
}
}
// This task should not be used - we don't use the "Unreleased" section anymore
project.gradle.startParameter.excludedTaskNames.add("patchChangeLog")
changelog {
val prospectiveReleaseVersion: String by extra
version.set("v$prospectiveReleaseVersion")
headerParserRegex.set(Regex("""v\d+\.\d+\.\d+"""))
path.set("${project.projectDir}/CHANGE-NOTES.md")
}
val verifyVersionTask = tasks.register("verifyChangeLogVersion") {
doLast {
val prospectiveVersionSection = changelog.version.get()
val latestVersionSection = changelog.getLatest()
if (prospectiveVersionSection != latestVersionSection.version) {
throw Exception(
"$prospectiveVersionSection is not the latest in CHANGE-NOTES.md, " +
"update the file or change the prospective version in version.gradle.kts",
)
}
}
}
val verifyContentsTask = tasks.register("verifyChangeLogContents") {
doLast {
val prospectiveVersionSection = changelog.get(changelog.version.get())
val renderItemStr = changelog.renderItem(prospectiveVersionSection)
if (renderItemStr.isBlank()) {
throw Exception("${prospectiveVersionSection.version} section is empty, update CHANGE-NOTES.md")
}
val listingElements = renderItemStr.split(System.lineSeparator()).drop(1)
for (line in listingElements) {
if (line.isNotBlank() && !line.startsWith("- ") && !line.startsWith(" ")) {
throw Exception(
"Update formatting in CHANGE-NOTES.md ${prospectiveVersionSection.version} section:" +
"${System.lineSeparator()}$line",
)
}
}
}
}
tasks.register("verifyChangeLog") {
dependsOn(verifyVersionTask, verifyContentsTask)
}
tasks.register("printPluginZipPath") {
doLast {
val buildPlugin = tasks.findByPath(":buildPlugin")!! as BuildPluginTask
println(buildPlugin.archiveFile.get().asFile.path)
}
}
tasks.register("printSignedPluginZipPath") {
// Querying the mapped value of map(task ':signPlugin' property 'archiveFile')
// before task ':buildPlugin' has completed is not supported
dependsOn(":buildPlugin")
doLast {
val signPlugin = tasks.findByPath(":signPlugin")!! as SignPluginTask
println(signPlugin.signedArchiveFile.get().asFile.path)
}
}
val verifyPluginZipTask = tasks.register("verifyPluginZip") {
val buildPlugin = tasks.findByPath(":buildPlugin")!! as BuildPluginTask
dependsOn(buildPlugin)
doLast {
val pluginZipPath = buildPlugin.archiveFile.get().asFile.path
val jarsInPluginZip = ZipFile(pluginZipPath).use { zf ->
zf.stream()
.map(ZipEntry::getName)
.map { it.removePrefix("git-machete-intellij-plugin/").removePrefix("lib/").removeSuffix(".jar") }
.filter { it.isNotEmpty() }
.toList()
}
for (proj in subprojects) {
val projJar = proj.path.replaceFirst(":", "").replace(":", "-")
val javaExtension = proj.extensions.findByType<JavaPluginExtension>()
val hasSourceCode = javaExtension?.sourceSets?.get("main")?.allSource?.srcDirs?.any { it.exists() } ?: false
if (hasSourceCode) {
check(projJar in jarsInPluginZip) {
"$projJar.jar was expected in plugin zip ($pluginZipPath) but was NOT found" +
"\nAll entries: $jarsInPluginZip"
}
} else {
check(projJar !in jarsInPluginZip) {
"$projJar.jar was NOT expected in plugin zip ($pluginZipPath) but was found" +
"\nAll entries: $jarsInPluginZip"
}
}
}
val expectedLibs = listOf("org.eclipse.jgit", "slf4j-lambda-core", "vavr", "vavr-match")
for (expectedLib in expectedLibs) {
val libRegexStr = "^" + expectedLib.replace(".", "\\.") + "-[0-9.]+.*$"
check(jarsInPluginZip.any { it.matches(libRegexStr.toRegex()) }) {
"A jar for $expectedLib was expected in plugin zip ($pluginZipPath) but was NOT found\nAll entries: $jarsInPluginZip"
}
}
val forbiddenLibPrefixes = listOf("idea", "kotlin", "lombok", "remote-robot", "slf4j")
for (jar in jarsInPluginZip) {
check(forbiddenLibPrefixes.none { jar.startsWith(it) } || expectedLibs.any { jar.startsWith(it) }) {
"$jar.jar was NOT expected in plugin zip ($pluginZipPath) but was found\nAll entries: $jarsInPluginZip"
}
}
}
}
tasks.named<Zip>("buildPlugin") {
dependsOn(verifyVersionTask)
finalizedBy(verifyPluginZipTask)
}
intellijPlatform {
buildSearchableOptions = false
instrumentCode = false
pluginConfiguration {
name = "Git Machete"
// Note that the first line of the description should be self-contained since it is placed into embeddable card:
// see e.g. https://plugins.jetbrains.com/search?search=git%20machete
description = file("$rootDir/DESCRIPTION.html").readText()
val changelogItem = changelog.getOrNull(changelog.version.get())
if (changelogItem != null) {
changeNotes = changelog.renderItem(changelogItem, Changelog.OutputType.HTML)
}
ideaVersion {
// `sinceBuild` is exclusive when we are using `*` in version but inclusive when without `*`
sinceBuild = intellijVersions.earliestSupportedMajor.toBuildNumber().value
// In `untilBuild` situation is inverted: it's inclusive when using `*` but exclusive when without `*`
untilBuild = intellijVersions.latestSupportedMajor.toBuildNumber().value + ".*"
}
}
signing {
certificateChain = pluginSignCertificateChain?.trimIndent()
privateKey = pluginSignPrivateKey?.trimIndent()
password = pluginSignPrivateKeyPass
}
publishing {
token = jetbrainsMarketplaceToken
}
pluginVerification {
ides {
// This could also be handled by `recommended()` DSL,
// but with this explicit approach, the IDE versions used for verification
// are fully controlled by repository contents (intellij-versions.properties),
// so the builds are more reproducible in this respect.
val maybeEap = listOfNotNull(intellijVersions.upcomingMajorEap)
val ideVersions = intellijVersions.latestMinorsOfOldSupportedMajors + intellijVersions.latestStable + maybeEap
ideVersions.map { it.value }.forEach {
create(it.productCode(), it)
}
}
failureLevel.set(
setOf(
VerifyPluginTask.FailureLevel.COMPATIBILITY_PROBLEMS,
VerifyPluginTask.FailureLevel.NON_EXTENDABLE_API_USAGES,
VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS,
VerifyPluginTask.FailureLevel.MISSING_DEPENDENCIES,
),
)
}
}
tasks.runIde {
jvmArgs("-Xmx20G")
}
dependencies {
intellijPlatform {
val productCode = intellijVersions.buildTarget.productCode()
// TODO (#2146): drop support for IntelliJ Community
if (productCode == "IU") {
intellijIdea(intellijVersions.buildTarget)
} else {
intellijIdeaCommunity(intellijVersions.buildTarget)
}
bundledPlugin("Git4Idea")
pluginVerifier()
zipSigner()
}
}
applyKotlinConfig()
archunit()
// Checker is needed in root project runtime (not just compile-time) classpath for ArchUnit tests
checkerQual("test")
jgit("test")
junit()
lombok("test")
vavr("test")
val uiTest = sourceSets.create("uiTest")
val uiTestImplementation by configurations.getting
val uiTestRuntimeOnly by configurations.getting
val robotServerPluginZip by configurations.creating
repositories {
maven {
url = URI("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies")
}
}
dependencies {
intellijPlatform {
// Note that theoretically, we should compile UI tests for each IDE version
// against test framework (ide-starter, driver-sdk etc.) for this particular version,
// as there's no guarantee that test framework version X will be compatible with IDE version Y for X != Y.
// See https://youtrack.jetbrains.com/issue/IJPL-234281.
// We're cutting corners here to keep the build setup simpler.
testFramework(TestFrameworkType.Starter, configurationName = uiTestImplementation.name)
}
junit("uiTest")
uiTestImplementation(testFixtures(project(":testCommon")))
uiTestImplementation(libs.kodein)
uiTestImplementation(libs.okhttp)
uiTestImplementation(libs.remoteRobot.client)
uiTestRuntimeOnly(libs.kotlin.coroutines)
robotServerPluginZip(libs.remoteRobot.serverPlugin) {
artifact {
type = "zip"
}
}
}
configureUiTests()