|
| 1 | +import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
| 2 | +import org.gradle.api.tasks.testing.logging.TestLogEvent |
| 3 | +import org.jetbrains.changelog.markdownToHTML |
| 4 | +import org.jetbrains.intellij.platform.gradle.TestFrameworkType |
| 5 | +import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES |
| 6 | +import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.INVALID_PLUGIN |
| 7 | +import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS |
| 8 | +import java.net.URI |
| 9 | +import java.text.SimpleDateFormat |
| 10 | +import java.util.Date |
| 11 | + |
| 12 | +fun properties(key: String) = project.findProperty(key).toString() |
| 13 | + |
| 14 | +fun isSnapshotBuild() = System.getenv("IJ_PLUGIN_SNAPSHOT").toBoolean() |
| 15 | + |
| 16 | +plugins { |
| 17 | + alias(libs.plugins.kotlin.jvm) |
| 18 | + alias(libs.plugins.intellij.platform) |
| 19 | + alias(libs.plugins.changelog) |
| 20 | + alias(libs.plugins.apollo) |
| 21 | + alias(libs.plugins.grammarkit) |
| 22 | +} |
| 23 | + |
| 24 | +repositories { |
| 25 | +// mavenLocal() |
| 26 | +// maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") |
| 27 | +// maven("https://storage.googleapis.com/apollo-previews/m2/") |
| 28 | + mavenCentral() |
| 29 | + |
| 30 | + intellijPlatform { |
| 31 | + defaultRepositories() |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +group = properties("pluginGroup") |
| 36 | + |
| 37 | +// Use the global version defined in the root project + dedicated suffix if building a snapshot from the CI |
| 38 | +version = properties("VERSION_NAME") + getSnapshotVersionSuffix() |
| 39 | + |
| 40 | +fun getSnapshotVersionSuffix(): String { |
| 41 | + if (!isSnapshotBuild()) return "" |
| 42 | + return ".${SimpleDateFormat("YYYY-MM-dd").format(Date())}." + System.getenv("GITHUB_SHA").take(7) |
| 43 | +} |
| 44 | + |
| 45 | +kotlin { |
| 46 | + jvmToolchain(21) |
| 47 | +} |
| 48 | + |
| 49 | +// Copy specific dependencies to a directory visible to the unit tests. |
| 50 | +// See ApolloTestCase.kt. |
| 51 | +configurations { |
| 52 | + create("apolloDependencies") |
| 53 | +} |
| 54 | +dependencies { |
| 55 | + listOf( |
| 56 | + libs.apollo.annotations, |
| 57 | + libs.apollo.api, |
| 58 | + libs.apollo.runtime, |
| 59 | + ).forEach { |
| 60 | + add("apolloDependencies", it) |
| 61 | + } |
| 62 | +} |
| 63 | +tasks.register<Copy>("copyApolloDependencies") { |
| 64 | + from(configurations.getByName("apolloDependencies")) |
| 65 | + into(layout.buildDirectory.asFile.get().resolve("apolloDependencies")) |
| 66 | +} |
| 67 | + |
| 68 | +tasks { |
| 69 | + val runLocalIde by intellijPlatformTesting.runIde.registering { |
| 70 | + // Use a custom IJ/AS installation. Set this property in your local ~/.gradle/gradle.properties file. |
| 71 | + // (for AS, it should be something like '/Applications/Android Studio.app/Contents') |
| 72 | + // See https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-gradle-build-script |
| 73 | + providers.gradleProperty("apolloIntellijPlugin.ideDir").orNull?.let { |
| 74 | + localPath.set(file(it)) |
| 75 | + } |
| 76 | + |
| 77 | + task { |
| 78 | + // Enables debug logging for the plugin |
| 79 | + systemProperty("idea.log.debug.categories", "Apollo") |
| 80 | + |
| 81 | + // Disable hiding frequent exceptions in logs (annoying for debugging). See com.intellij.idea.IdeaLogger. |
| 82 | + systemProperty("idea.logger.exception.expiration.minutes", "0") |
| 83 | + |
| 84 | + // Uncomment to disable internal mode - see https://plugins.jetbrains.com/docs/intellij/enabling-internal.html |
| 85 | + // systemProperty("idea.is.internal", "false") |
| 86 | + |
| 87 | + // Enable K2 mode (can't be done in the UI in sandbox mode - see https://kotlin.github.io/analysis-api/testing-in-k2-locally.html) |
| 88 | + systemProperty("idea.kotlin.plugin.use.k2", "true") |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + withType<AbstractTestTask> { |
| 93 | + // Log tests |
| 94 | + testLogging { |
| 95 | + exceptionFormat = TestExceptionFormat.FULL |
| 96 | + events.add(TestLogEvent.PASSED) |
| 97 | + events.add(TestLogEvent.FAILED) |
| 98 | + showStandardStreams = true |
| 99 | + } |
| 100 | + dependsOn("copyApolloDependencies") |
| 101 | + dependsOn(":test-project:generateApolloSources") |
| 102 | + } |
| 103 | + |
| 104 | + generateLexer { |
| 105 | + purgeOldFiles.set(true) |
| 106 | + sourceFile.set(file("src/main/grammars/ApolloGraphQLLexer.flex")) |
| 107 | + targetOutputDir.set(file("src/main/java/com/apollographql/ijplugin/psi")) |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +// Setup fake JDK for maven dependencies to work |
| 112 | +// See https://youtrack.jetbrains.com/issue/IJSDK-321 |
| 113 | +val mockJdkRoot = layout.buildDirectory.asFile.get().resolve("mockJDK") |
| 114 | +tasks.register("downloadMockJdk") { |
| 115 | + val mockJdkRoot = mockJdkRoot |
| 116 | + doLast { |
| 117 | + val rtJar = mockJdkRoot.resolve("java/mockJDK-1.7/jre/lib/rt.jar") |
| 118 | + if (!rtJar.exists()) { |
| 119 | + rtJar.parentFile.mkdirs() |
| 120 | + rtJar.writeBytes( |
| 121 | + URI("https://github.com/JetBrains/intellij-community/raw/master/java/mockJDK-1.7/jre/lib/rt.jar").toURL() |
| 122 | + .openStream() |
| 123 | + .readBytes() |
| 124 | + ) |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +tasks.test.configure { |
| 130 | + // Setup fake JDK for maven dependencies to work |
| 131 | + // See https://jetbrains-platform.slack.com/archives/CPL5291JP/p1664105522154139 and https://youtrack.jetbrains.com/issue/IJSDK-321 |
| 132 | + // Use a relative path to make build caching work |
| 133 | + dependsOn("downloadMockJdk") |
| 134 | + systemProperty("idea.home.path", mockJdkRoot.relativeTo(project.projectDir).path) |
| 135 | + |
| 136 | + // Enable K2 mode - see https://kotlin.github.io/analysis-api/testing-in-k2-locally.html |
| 137 | + systemProperty("idea.kotlin.plugin.use.k2", "true") |
| 138 | +} |
| 139 | + |
| 140 | +apollo { |
| 141 | + service("apolloDebugServer") { |
| 142 | + packageName.set("com.apollographql.ijplugin.apollodebugserver") |
| 143 | + introspection { |
| 144 | + endpointUrl.set("http://localhost:12200/") |
| 145 | + schemaFile.set(file("src/main/graphql/schema.graphqls")) |
| 146 | + } |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +dependencies { |
| 151 | + // IntelliJ Platform dependencies must be declared before the intellijPlatform block - see https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1784 |
| 152 | + intellijPlatform { |
| 153 | + create(type = properties("platformType"), version = properties("platformVersion")) |
| 154 | + bundledPlugins(properties("platformBundledPlugins").split(',').map(String::trim).filter(String::isNotEmpty)) |
| 155 | + plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty)) |
| 156 | + // Use a specific version of the verifier |
| 157 | + // TODO: remove when https://youtrack.jetbrains.com/issue/MP-7366 is fixed |
| 158 | + pluginVerifier(version = "1.383") |
| 159 | + testFramework(TestFrameworkType.Plugin.Java) |
| 160 | + zipSigner() |
| 161 | + } |
| 162 | + |
| 163 | + implementation(libs.apollo.gradle.plugin.external) { |
| 164 | + exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") |
| 165 | + } |
| 166 | + implementation(libs.apollo.ast) |
| 167 | + implementation(libs.apollo.tooling) { |
| 168 | + exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") |
| 169 | + } |
| 170 | + implementation(libs.apollo.normalized.cache.sqlite.classic) |
| 171 | + implementation(libs.sqlite.jdbc) |
| 172 | + implementation(libs.apollo.normalized.cache.sqlite.new) { |
| 173 | + exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") |
| 174 | + } |
| 175 | + implementation(libs.apollo.runtime) { |
| 176 | + exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") |
| 177 | + } |
| 178 | + runtimeOnly(libs.slf4j.simple) |
| 179 | + testImplementation(libs.google.testparameterinjector) |
| 180 | + |
| 181 | + // Temporary workaround for https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1663 |
| 182 | + // Should be fixed in platformVersion 2024.3.x |
| 183 | + testRuntimeOnly("org.opentest4j:opentest4j:1.3.0") |
| 184 | +} |
| 185 | + |
| 186 | +// IntelliJ Platform Gradle Plugin configuration |
| 187 | +// See https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html#intellijPlatform-pluginConfiguration |
| 188 | +intellijPlatform { |
| 189 | + pluginConfiguration { |
| 190 | + id.set(properties("pluginId")) |
| 191 | + name.set(properties("pluginName")) |
| 192 | + version.set(project.version.toString()) |
| 193 | + ideaVersion { |
| 194 | + sinceBuild = properties("pluginSinceBuild") |
| 195 | + // No untilBuild specified, the plugin wants to be compatible with all future versions |
| 196 | + untilBuild = provider { null } |
| 197 | + } |
| 198 | + // Extract the <!-- Plugin description --> section from README.md and provide it to the plugin's manifest |
| 199 | + description.set( |
| 200 | + projectDir.resolve("../README.md").readText().lines().run { |
| 201 | + val start = "<!-- Plugin description -->" |
| 202 | + val end = "<!-- Plugin description end -->" |
| 203 | + |
| 204 | + if (!containsAll(listOf(start, end))) { |
| 205 | + throw GradleException("Plugin description section not found in README.md:\n$start ... $end") |
| 206 | + } |
| 207 | + subList(indexOf(start) + 1, indexOf(end)) |
| 208 | + }.joinToString("\n").run { markdownToHTML(this) } |
| 209 | + ) |
| 210 | + changeNotes.set( |
| 211 | + if (isSnapshotBuild()) { |
| 212 | + "Weekly snapshot builds contain the latest changes from the <code>main</code> branch." |
| 213 | + } else { |
| 214 | + "See the <a href=\"https://github.com/apollographql/apollo-kotlin/releases/tag/v${project.version}\">release notes</a>." |
| 215 | + } |
| 216 | + ) |
| 217 | + } |
| 218 | + |
| 219 | + signing { |
| 220 | + certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) |
| 221 | + privateKey.set(System.getenv("PRIVATE_KEY")) |
| 222 | + password.set(System.getenv("PRIVATE_KEY_PASSWORD")) |
| 223 | + } |
| 224 | + |
| 225 | + publishing { |
| 226 | + token.set(System.getenv("PUBLISH_TOKEN")) |
| 227 | + if (isSnapshotBuild()) { |
| 228 | + // Read more: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html#specifying-a-release-channel |
| 229 | + channels.set(listOf("snapshots")) |
| 230 | + } |
| 231 | + } |
| 232 | + |
| 233 | + pluginVerification { |
| 234 | + ides { |
| 235 | + recommended() |
| 236 | + } |
| 237 | + failureLevel.set( |
| 238 | + setOf( |
| 239 | + // Temporarily disabled due to https://platform.jetbrains.com/t/plugin-verifier-fails-with-plugin-com-intellij-modules-json-not-declared-as-a-plugin-dependency/580 |
| 240 | + // TODO: Uncomment when https://youtrack.jetbrains.com/issue/MP-7366 is fixed |
| 241 | + // COMPATIBILITY_PROBLEMS, |
| 242 | + INTERNAL_API_USAGES, |
| 243 | + INVALID_PLUGIN, |
| 244 | + PLUGIN_STRUCTURE_WARNINGS, |
| 245 | + ) |
| 246 | + ) |
| 247 | + } |
| 248 | +} |
0 commit comments