-
Notifications
You must be signed in to change notification settings - Fork 669
/
Copy pathbuild.gradle.kts
258 lines (222 loc) · 9.82 KB
/
build.gradle.kts
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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.INVALID_PLUGIN
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import java.net.URI
import java.text.SimpleDateFormat
import java.util.Date
fun properties(key: String) = project.findProperty(key).toString()
fun isSnapshotBuild() = System.getenv("IJ_PLUGIN_SNAPSHOT").toBoolean()
plugins {
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.intellij.platform")
alias(libs.plugins.apollo.published)
alias(libs.plugins.grammarkit)
}
commonSetup()
// XXX: this should use the settings repositories instead
repositories {
// Uncomment this one to use the Kotlin "dev" repository
maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") }
// Uncomment this one to use the Sonatype OSSRH snapshots repository
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}
group = properties("pluginGroup")
// Use the global version defined in the root project + dedicated suffix if building a snapshot from the CI
version = properties("VERSION_NAME") + getSnapshotVersionSuffix()
fun getSnapshotVersionSuffix(): String {
if (!isSnapshotBuild()) return ""
return ".${SimpleDateFormat("YYYY-MM-dd").format(Date())}." + System.getenv("GITHUB_SHA").take(7)
}
// Set the JVM language level used to build project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
val apolloDependencies = configurations.create("apolloDependencies").apply {
attributes {
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
}
listOf(":apollo-annotations", ":apollo-api", ":apollo-runtime").forEach {
dependencies.add(project.dependencies.project(it, "jvmApiElements"))
}
}
tasks {
val runLocalIde by intellijPlatformTesting.runIde.registering {
// Use a custom IJ/AS installation. Set this property in your local ~/.gradle/gradle.properties file.
// (for AS, it should be something like '/Applications/Android Studio.app/Contents')
// See https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-gradle-build-script
providers.gradleProperty("apolloIntellijPlugin.ideDir").orNull?.let {
localPath.set(file(it))
}
task {
// Enables debug logging for the plugin
systemProperty("idea.log.debug.categories", "Apollo")
// Disable hiding frequent exceptions in logs (annoying for debugging). See com.intellij.idea.IdeaLogger.
systemProperty("idea.logger.exception.expiration.minutes", "0")
// Uncomment to disable internal mode - see https://plugins.jetbrains.com/docs/intellij/enabling-internal.html
// systemProperty("idea.is.internal", "false")
// 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)
systemProperty("idea.kotlin.plugin.use.k2", "true")
}
}
// Log tests
withType<AbstractTestTask> {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events.add(TestLogEvent.PASSED)
events.add(TestLogEvent.FAILED)
showStandardStreams = true
}
inputs.files(apolloDependencies)
}
generateLexer {
purgeOldFiles.set(true)
sourceFile.set(file("src/main/grammars/ApolloGraphQLLexer.flex"))
targetOutputDir.set(file("src/main/java/com/apollographql/ijplugin/psi"))
}
}
val mockJdkRoot = layout.buildDirectory.asFile.get().resolve("mockJDK")
// Setup fake JDK for maven dependencies to work
// See https://jetbrains-platform.slack.com/archives/CPL5291JP/p1664105522154139 and https://youtrack.jetbrains.com/issue/IJSDK-321
tasks.register("downloadMockJdk") {
val mockJdkRoot = mockJdkRoot
doLast {
val rtJar = mockJdkRoot.resolve("java/mockJDK-1.7/jre/lib/rt.jar")
if (!rtJar.exists()) {
rtJar.parentFile.mkdirs()
rtJar.writeBytes(URI("https://github.com/JetBrains/intellij-community/raw/master/java/mockJDK-1.7/jre/lib/rt.jar").toURL()
.openStream()
.readBytes()
)
}
}
}
tasks.test.configure {
dependsOn("downloadMockJdk")
// Setup fake JDK for maven dependencies to work
// See https://jetbrains-platform.slack.com/archives/CPL5291JP/p1664105522154139 and https://youtrack.jetbrains.com/issue/IJSDK-321
// Use a relative path to make build caching work
systemProperty("idea.home.path", mockJdkRoot.relativeTo(project.projectDir).path)
// Enable K2 mode - see https://kotlin.github.io/analysis-api/testing-in-k2-locally.html
systemProperty("idea.kotlin.plugin.use.k2", "true")
}
apollo {
service("apolloDebugServer") {
packageName.set("com.apollographql.ijplugin.apollodebugserver")
schemaFiles.from(file("../libraries/apollo-debug-server/graphql/schema.graphqls"))
introspection {
endpointUrl.set("http://localhost:12200/")
schemaFile.set(file("../libraries/apollo-debug-server/graphql/schema.graphqls"))
}
}
}
// We're using project(":apollo-gradle-plugin-external") and the published "apollo-runtime" which do not have the same version
tasks.configureEach {
if (name == "checkApolloVersions") {
enabled = false
}
}
val apolloPublished = configurations.dependencyScope("apolloPublished").get()
configurations.getByName("implementation").extendsFrom(apolloPublished)
dependencies {
// IntelliJ Platform dependencies must be declared before the intellijPlatform block - see https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1784
intellijPlatform {
create(type = properties("platformType"), version = properties("platformVersion"))
bundledPlugins(properties("platformBundledPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
instrumentationTools()
pluginVerifier()
testFramework(TestFrameworkType.Plugin.Java)
zipSigner()
}
// Coroutines must be excluded to avoid a conflict with the version bundled with the IDE
// See https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#coroutinesLibraries
implementation(project(":apollo-gradle-plugin-external")) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
}
implementation(project(":apollo-ast"))
implementation(project(":apollo-tooling")) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
}
implementation(project(":apollo-normalized-cache-sqlite"))
implementation(libs.sqlite.jdbc)
implementation(libs.apollo.normalizedcache.sqlite.incubating) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
}
add("apolloPublished", libs.apollo.runtime.published.get().toString()) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
}
runtimeOnly(libs.slf4j.simple)
testImplementation(libs.google.testparameterinjector)
// Temporary workaround for https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1663
// Should be fixed in platformVersion 2024.3.x
testRuntimeOnly("org.opentest4j:opentest4j:1.3.0")
}
// IntelliJ Platform Gradle Plugin configuration
// See https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html#intellijPlatform-pluginConfiguration
intellijPlatform {
pluginConfiguration {
id.set(properties("pluginId"))
name.set(properties("pluginName"))
version.set(project.version.toString())
ideaVersion {
sinceBuild = properties("pluginSinceBuild")
// No untilBuild specified, the plugin wants to be compatible with all future versions
untilBuild = provider { null }
}
// Extract the <!-- Plugin description --> section from README.md and provide it to the plugin's manifest
description.set(
projectDir.resolve("README.md").readText().lines().run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end))
}.joinToString("\n").run { markdownToHTML(this) }
)
changeNotes.set(
if (isSnapshotBuild()) {
"Weekly snapshot builds contain the latest changes from the <code>main</code> branch."
} else {
"See the <a href=\"https://github.com/apollographql/apollo-kotlin/releases/tag/v${project.version}\">release notes</a>."
}
)
}
signing {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
publishing {
token.set(System.getenv("PUBLISH_TOKEN"))
if (isSnapshotBuild()) {
// Read more: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html#specifying-a-release-channel
channels.set(listOf("snapshots"))
}
}
pluginVerification {
ides {
recommended()
}
failureLevel.set(
setOf(
// TODO: 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
// COMPATIBILITY_PROBLEMS,
INTERNAL_API_USAGES,
INVALID_PLUGIN,
PLUGIN_STRUCTURE_WARNINGS,
)
)
}
}