-
Notifications
You must be signed in to change notification settings - Fork 343
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
556 lines (497 loc) · 19.3 KB
/
build.gradle.kts
File metadata and controls
556 lines (497 loc) · 19.3 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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
/*
* Copyright 2024 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
import okhttp3.internal.immutableListOf
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.changelog.Changelog
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.models.ProductRelease
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
// Specify UTF-8 for all compilations so we avoid Windows-1252.
allprojects {
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<Test> {
systemProperty("file.encoding", "UTF-8")
}
}
repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/packages.jetbrains.team/maven/p/ij/intellij-ide-starter")
maven("https://mvnrepository.com/artifact/com.jetbrains.intellij.tools/ide-starter-driver")
intellijPlatform {
defaultRepositories()
}
}
plugins {
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html
// https://plugins.gradle.org/plugin/org.jetbrains.intellij.platform
// https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm
id("java") // Java support
alias(libs.plugins.intellij.platform) // IntelliJ Platform Gradle Plugin
alias(libs.plugins.kotlin.jvm) // Kotlin support
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.kover)
idea // IntelliJ IDEA support
}
// By default (e.g. when we call `runIde` during development), the plugin version is SNAPSHOT
var flutterPluginVersion = "SNAPSHOT"
val isRelease = providers.gradleProperty("release").isPresent
val isDev = providers.gradleProperty("dev").isPresent
val singleIdeVersionProvider = providers.gradleProperty("singleIdeVersion")
// Otherwise, we will decide on the proper semver-formatted version from the CHANGELOG.
// Note: The CHANGELOG follows the style from https://keepachangelog.com/en/1.0.0/ so that we can use the gradle changelog plugin.
if (isRelease) {
// If we are building for a release, the changelog should be updated with the latest version.
flutterPluginVersion = changelog.getLatest().version
} else if (isDev) {
// If we are building the dev version, the version label will increment the latest version from the changelog and append the date.
val latestVersion = changelog.getLatest().version
val majorVersion = latestVersion.substringBefore('.').toInt()
val nextMajorVersion = majorVersion + 1
val datestamp = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now())
flutterPluginVersion = "$nextMajorVersion.0.0-dev.$datestamp"
val commitHash = System.getenv("KOKORO_GIT_COMMIT") ?: try {
providers.exec {
commandLine("git", "rev-parse", "--short", "HEAD")
}.standardOutput.asText.get().trim()
} catch (e: Exception) {
// Catching all exceptions here is intentional: if git is not installed, or if this is built
// outside of a git repository clone (e.g. from a source zip release), we want the build
// to gracefully proceed with an empty hash instead of crashing.
""
}
if (commitHash.isNotEmpty()) {
val shortCommitHash = commitHash.take(7)
flutterPluginVersion += "-$shortCommitHash"
}
}
val androidStudioVersion = providers.gradleProperty("androidStudioVersion").get()
val dartPluginVersion = providers.gradleProperty("dartPluginVersion").get()
val sinceBuildInput = providers.gradleProperty("sinceBuild").get()
val untilBuildInput = providers.gradleProperty("untilBuild").get()
val javaVersion = providers.gradleProperty("javaVersion").get()
group = "io.flutter"
// For debugging purposes:
println("flutterPluginVersion: $flutterPluginVersion")
println("androidStudioVersion: $androidStudioVersion")
println("dartPluginVersion: $dartPluginVersion")
println("sinceBuild: $sinceBuildInput")
println("untilBuild: $untilBuildInput")
println("javaVersion: $javaVersion")
println("group: $group")
var jvmVersion: JvmTarget
jvmVersion = when (javaVersion) {
"17" -> {
JvmTarget.JVM_17
}
"21" -> {
JvmTarget.JVM_21
}
else -> {
throw IllegalArgumentException("javaVersion must be defined in the product matrix as either \"17\" or \"21\", but is not for $androidStudioVersion")
}
}
kotlin {
compilerOptions {
apiVersion.set(KotlinVersion.KOTLIN_2_1)
jvmTarget = jvmVersion
}
// This is how you specify the specific JVM requirements, this may be a requirement for the Starter test framework
// jvmToolchain {
// languageVersion = JavaLanguageVersion.of(21)
// @Suppress("UnstableApiUsage")
// vendor = JvmVendorSpec.JETBRAINS
// }
}
var javaCompatibilityVersion: JavaVersion
javaCompatibilityVersion = when (javaVersion) {
"17" -> {
JavaVersion.VERSION_17
}
"21" -> {
JavaVersion.VERSION_21 // all later versions of java can build against the earlier versions
}
else -> {
throw IllegalArgumentException("javaVersion must be defined in the product matrix as either \"17\" or \"21\", but is not for $androidStudioVersion")
}
}
java {
sourceCompatibility = javaCompatibilityVersion
targetCompatibility = javaCompatibilityVersion
}
sourceSets {
main {
java.srcDirs(
listOf(
"src",
"third_party/vmServiceDrivers"
)
)
kotlin.srcDirs(
listOf(
"src",
"third_party/vmServiceDrivers"
)
)
// Add kotlin.srcDirs if we start using Kotlin in the main plugin.
resources.srcDirs(
listOf(
"src",
"resources"
)
)
}
test {
java.srcDirs(
listOf(
"testSrc/unit"
)
)
resources.srcDirs(
listOf(
"resources",
"testData",
"testSrc/unit"
)
)
}
create("integration", Action<SourceSet> {
java.srcDirs("testSrc/integration")
kotlin.srcDirs("testSrc/integration")
resources.srcDirs("testSrc/integration")
compileClasspath += sourceSets["main"].output + sourceSets["test"].output
runtimeClasspath += sourceSets["main"].output + sourceSets["test"].output
})
}
// Configure IntelliJ IDEA to recognize integration as test sources
idea {
module {
testSources.from(sourceSets["integration"].kotlin.srcDirs)
testResources.from(sourceSets["integration"].resources.srcDirs)
}
}
val integrationImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val integrationRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}
dependencies {
intellijPlatform {
// Documentation on the default target platform methods:
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html#default-target-platforms
// Android Studio versions can be found at: https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
try {
androidStudio(androidStudioVersion)
} catch (e: Exception) {
throw GradleException(
"Failed to resolve Android Studio / IDEA download URL. This is likely due to a network issue blocking the download URL. Please check your internet connection or VPN.",
e
)
}
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.Starter, configurationName = "integrationImplementation")
testFramework(TestFrameworkType.JUnit5, configurationName = "integrationImplementation")
// Plugin dependency documentation:
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html#plugins
// https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#project-setup
bundledPlugins(
immutableListOf(
"com.intellij.java",
"com.intellij.properties",
"JUnit",
"Git4Idea",
"org.jetbrains.kotlin",
"org.jetbrains.plugins.gradle",
"org.jetbrains.plugins.yaml",
"org.jetbrains.android",
"com.android.tools.idea.smali"
)
)
plugin("Dart:$dartPluginVersion")
plugin("com.redhat.devtools.lsp4ij:${libs.versions.lsp4ij.get()}")
bundledModule("intellij.platform.langInjection")
bundledModule("intellij.platform.coverage")
bundledModule("intellij.platform.coverage.agent")
pluginVerifier()
}
compileOnly(libs.jetbrains.annotations)
testImplementation(libs.jetbrains.annotations)
compileOnly(libs.guava.android)
compileOnly(libs.gson)
testImplementation(libs.guava.jre)
testImplementation(libs.gson)
testImplementation(libs.junit)
testImplementation(libs.bytebuddy)
implementation(
fileTree(
mapOf(
"dir" to "${project.rootDir}/third_party/lib/jxbrowser",
"include" to listOf("*.jar")
)
)
)
// UI Test dependencies
integrationImplementation(libs.kodein.di)
integrationImplementation(libs.kotlinx.coroutines)
// JUnit 5 is required for UI tests
integrationImplementation(libs.junit.jupiter)
integrationRuntimeOnly(libs.junit.platform.launcher)
}
intellijPlatform {
pluginConfiguration {
version = flutterPluginVersion
ideaVersion {
sinceBuild = sinceBuildInput
untilBuild = untilBuildInput
}
changeNotes = provider {
project.changelog.renderItem(project.changelog.getLatest(), Changelog.OutputType.HTML)
}
}
// Verifier documentation
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html#intellijPlatform-pluginVerification
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html#intellijPlatform-pluginVerification-ides
pluginVerification {
// https://github.com/JetBrains/intellij-plugin-verifier/?tab=readme-ov-file#specific-options
// https://github.com/JetBrains/intellij-plugin-verifier
cliPath = file("./third_party/lib/verifier-cli-1.398-all.jar")
failureLevel = listOf(
// TODO(team) Ideally all of the following FailureLevels should be enabled:
// https://github.com/flutter/flutter-intellij/issues/8361
VerifyPluginTask.FailureLevel.COMPATIBILITY_WARNINGS,
VerifyPluginTask.FailureLevel.COMPATIBILITY_PROBLEMS,
// VerifyPluginTask.FailureLevel.DEPRECATED_API_USAGES, // https://github.com/flutter/flutter-intellij/issues/7718
// VerifyPluginTask.FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
VerifyPluginTask.FailureLevel.EXPERIMENTAL_API_USAGES,
// VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES,
// VerifyPluginTask.FailureLevel.OVERRIDE_ONLY_API_USAGES,
VerifyPluginTask.FailureLevel.NON_EXTENDABLE_API_USAGES,
VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS,
VerifyPluginTask.FailureLevel.MISSING_DEPENDENCIES,
VerifyPluginTask.FailureLevel.INVALID_PLUGIN,
// VerifyPluginTask.FailureLevel.NOT_DYNAMIC,
)
verificationReportsFormats = VerifyPluginTask.VerificationReportsFormats.ALL
subsystemsToCheck = VerifyPluginTask.Subsystems.ALL
ignoredProblemsFile.set(project.file("verify-ignore-problems.txt"))
ides {
// `singleIdeVersion` is only intended for use by GitHub actions to enable deleting instances of IDEs after testing.
if (singleIdeVersionProvider.isPresent) {
val singleIdeVersion = singleIdeVersionProvider.get()
select {
types = listOf(IntelliJPlatformType.AndroidStudio)
channels = listOf(ProductRelease.Channel.RELEASE)
sinceBuild = singleIdeVersion
untilBuild = "$singleIdeVersion.*"
}
} else {
recommended()
}
}
}
}
// If we don't delete old versions of the IDE during `verifyPlugin`, then GitHub action bots can run out of space.
tasks.withType<VerifyPluginTask> {
if (singleIdeVersionProvider.isPresent) {
doLast {
ides.forEach { ide ->
if (ide.exists()) {
// This isn't a clean deletion because gradle has internal logic for tagging that it has downloaded something, and the tagging
// isn't deleted. So if we were to run `./gradlew verifyPlugin -PsingleIdeVersion=<someVersion` twice in a row, the second time
// would fail due to gradle thinking that there should be an IDE at a place it recorded from the last run.
println("Deleting IDE directory at ${ide.path}")
val result = ide.deleteRecursively()
println("IDE was deleted? $result")
}
}
}
}
}
tasks {
register<Test>("integration") {
description = "Runs only the UI integration tests that start the IDE"
group = "verification"
testClassesDirs = sourceSets["integration"].output.classesDirs
classpath = sourceSets["integration"].runtimeClasspath
useJUnitPlatform {
includeTags("ui")
}
// UI tests should run sequentially (not in parallel) to avoid conflicts
maxParallelForks = 1
// Increase memory for UI tests
minHeapSize = "1g"
maxHeapSize = "4g"
systemProperty("path.to.build.plugin", buildPlugin.get().archiveFile.get().asFile.absolutePath)
systemProperty("idea.home.path", providers.provider {
try {
prepareTestSandbox.get().destinationDir.parentFile.absolutePath
} catch (e: Exception) {
throw GradleException(
"Failed to resolve Android Studio/ IDEA path. This is likely due to a network issue blocking the download URL. Please check your internet connection or VPN.",
e
)
}
})
systemProperty(
"allure.results.directory", project.layout.buildDirectory.get().asFile.absolutePath + "/allure-results"
)
// Disable IntelliJ test listener that conflicts with standard JUnit
systemProperty("idea.test.cyclic.buffer.size", "0")
// Add required JVM arguments
jvmArgumentProviders += CommandLineArgumentProvider {
mutableListOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.desktop/javax.swing=ALL-UNNAMED"
)
}
dependsOn(buildPlugin)
}
}
// Documentation for printProductsReleases:
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#how-to-check-the-latest-available-eap-release
tasks {
printProductsReleases {
channels = listOf(ProductRelease.Channel.RELEASE, ProductRelease.Channel.EAP)
types = listOf(IntelliJPlatformType.IntellijIdeaCommunity, IntelliJPlatformType.IntellijIdeaUltimate, IntelliJPlatformType.AndroidStudio)
untilBuild = provider { null }
doLast {
productsReleases.get().max()
println()
println("Mapping printProductsReleases output to ideV:")
println(" - The prefix (e.g., IU-, IC-, AI-) maps to -Pide (Ultimate, IntelliJ, Android Studio).")
println(" - The number part (e.g., 261.23567.71) maps to -PideV.")
println(" - Example: IU-261.23567.71 -> -Pide=Ultimate -PideV=261.23567.71")
println(" - Example: AI-2025.3.3.6 -> -Pide=AndroidStudio -PideV=2025.3.3.6")
println()
}
}
prepareJarSearchableOptions {
enabled = false
}
buildSearchableOptions {
enabled = false
}
test {
useJUnit()
testLogging {
showCauses = true
showStackTraces = true
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
events("skipped", "failed")
}
}
}
intellijPlatformTesting {
runIde {
register("runTarget") {
val target = project.findProperty("ide") as? String
val version = project.findProperty("ideV") as? String
val actualTarget = target ?: "AndroidStudio"
type = when (actualTarget) {
"IntelliJ" -> IntelliJPlatformType.IntellijIdeaCommunity
"Ultimate" -> IntelliJPlatformType.IntellijIdeaUltimate
else -> IntelliJPlatformType.AndroidStudio
}
this.version = version ?: androidStudioVersion
}
}
}
tasks.named("runTarget") {
val target = project.findProperty("ide") as? String
val version = project.findProperty("ideV") as? String
doFirst {
if (target == null && version == null) {
println("============================================================")
println("runTarget - Available Options")
println("============================================================")
println("Valid values for -Pide:")
println(" - AndroidStudio (default)")
println(" - IntelliJ (IntelliJ IDEA Community)")
println(" - Ultimate (IntelliJ IDEA Ultimate)")
println()
println("Valid values for -PideV:")
println(" - Any valid version string for the selected IDE.")
println(" - Examples for IntelliJ/Ultimate: 2024.1, 2024.2, 2024.3, 2025.1")
println(" - Run './gradlew printProductsReleases' to see the full list.")
println()
println("Examples:")
println(" ./gradlew runTarget -Pide=IntelliJ -PideV=2025.1")
println(" ./gradlew runTarget -Pide=Ultimate -PideV=2025.1")
println("============================================================")
println("Stopping execution. Please run with parameters to launch a specific IDE.")
throw org.gradle.api.tasks.StopExecutionException()
}
}
}
// A task to print the classpath used for compiling an IntelliJ plugin
// Run with `./gradlew printCompileClasspath --no-configuration-cache `
tasks.register<Task>("printCompileClasspath") {
doLast {
println("--- Begin Compile Classpath ---")
configurations.getByName("compileClasspath").forEach { file ->
println(file.absolutePath)
}
println("--- End Compile Classpath ---")
}
}
// This finds the JxBrowser license key from the environment and writes it to a file.
// This is only used by the dev build on kokoro for now.
val writeLicenseKey = tasks.register<Task>("writeLicenseKey") {
group = "build"
description = "Writes the license key from an environment variable to a file."
// Find the output file
val outputDir = rootProject.file("resources/jxbrowser")
val licenseFile = outputDir.resolve("jxbrowser.properties")
outputs.file(licenseFile)
doLast {
// Read the license key from the environment variable
val base = System.getenv("KOKORO_KEYSTORE_DIR")
val id = System.getenv("FLUTTER_KEYSTORE_ID")
val name = System.getenv("FLUTTER_KEYSTORE_JXBROWSER_KEY_NAME")
val readFile = File(base + "/" + id + "_" + name)
if (readFile.isFile) {
val licenseKey = readFile.readText(Charsets.UTF_8)
licenseFile.writeText("jxbrowser.license.key=$licenseKey")
}
}
}
tasks.named("buildPlugin") {
dependsOn(writeLicenseKey)
}
tasks.named("processResources") {
dependsOn(writeLicenseKey)
}
// TODO(helin24): Find a better way to skip checking this file for tests.
tasks.withType<ProcessResources>().configureEach {
if (name == "processTestResources") {
// This block will only execute for the 'processTestResources' task.
// The context here is unambiguously the task itself.
exclude("jxbrowser/jxbrowser.properties")
}
}
abstract class PrintVersionTask : DefaultTask() {
@get:Input
abstract val pluginVersion: Property<String>
@TaskAction
fun action() {
println(pluginVersion.get())
}
}
tasks.register<PrintVersionTask>("printVersion") {
pluginVersion.set(intellijPlatform.pluginConfiguration.version)
}