-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.gradle.kts
235 lines (209 loc) · 7.84 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
import org.jetbrains.changelog.Changelog
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.FailureLevel
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.EnumSet
plugins {
id("java")
kotlin("jvm") version embeddedKotlinVersion
alias(libs.plugins.jetbrains.intellij.platform)
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.jetbrains.grammarkit)
id("local.bump-version")
id("local.jbr-guidance")
}
// Import variables from gradle.properties file
val pluginGroup: String by project
val pluginName: String by project
val pluginVersion: String by project
val pluginSinceBuild: String by project
val pluginUntilBuild: String by project
val platformType: String by project
val platformVersion: String by project
group = pluginGroup
version = pluginVersion
java {
// Don't use Gradle's toolchain feature as it prevents building the project with more recent JDKs. Related issues:
// https://github.com/gradle/gradle/issues/16256 - Ability to set a min language version for a toolchain
// https://github.com/gradle/gradle/issues/17444 - Toolchains feature does not appear to treat Java as backwards compatible
// https://github.com/gradle/gradle/issues/18894 - More flexibility in querying Java toolchains
sourceCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
// Configure project's dependencies
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}
dependencies {
compileOnly(libs.jetbrains.annotations)
testImplementation(platform(libs.junit5.bom))
testImplementation(libs.junit5.jupiter)
testImplementation(libs.junit5.platform.testkit)
testImplementation(libs.junit4)
testRuntimeOnly(libs.junit5.vintage.engine)
intellijPlatform {
create(platformType, platformVersion)
testFramework(TestFrameworkType.Platform)
//testFramework(TestFrameworkType.JUnit5)
instrumentationTools()
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
pluginVerifier("1.307")
}
}
// Configure intellij-platform-gradle-plugin plugin.
// Read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
intellijPlatform {
projectName = pluginName
pluginConfiguration {
id = "nix-idea"
name = "NixIDEA"
version = pluginVersion
vendor {
name = "NixOS"
}
ideaVersion {
sinceBuild = pluginSinceBuild
untilBuild = pluginUntilBuild
}
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
description = providers.provider {
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) }
}
// Get the latest available change notes from the changelog file
changeNotes = provider {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML
)
}
}
}
pluginVerification {
ides {
ides(
providers.gradleProperty("verifierIdeVersionOverride")
// Verify only against the IDE specified by the property
.map { listOf(it) }
// If property is not set, verify against the recommended list of IDEs
.orElse(ProductReleasesValueSource())
)
}
failureLevel = EnumSet.complementOf(
EnumSet.of(
FailureLevel.DEPRECATED_API_USAGES,
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
FailureLevel.EXPERIMENTAL_API_USAGES,
)
)
}
publishing {
token = providers.environmentVariable("JETBRAINS_TOKEN")
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
}
}
changelog {
repositoryUrl = "https://github.com/NixOS/nix-idea"
lineSeparator = "\n"
// Workarounds because our version numbers do not match the format of semantic versioning:
headerParserRegex = "^[-._+0-9a-zA-Z]+\$"
combinePreReleases = false
}
grammarKit {
// version of IntelliJ patched JFlex
// -> https://github.com/JetBrains/intellij-deps-jflex
jflexRelease = "1.9.2"
// tag or short commit hash of Grammar-Kit to use
// -> https://github.com/JetBrains/Grammar-Kit
grammarKitRelease = "2022.3.2"
}
val lexerSource = layout.buildDirectory.dir("generated/sources/lexer/java/main")
sourceSets {
main {
java {
srcDir(lexerSource)
srcDir(tasks.generateParser)
}
}
}
tasks {
val runIntellij by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.IntellijIdeaCommunity
}
withType<JavaCompile> {
options.encoding = "UTF-8"
}
withType<Javadoc> {
options.encoding = "UTF-8"
}
withType<Test> {
systemProperty("idea.test.execution.policy", "org.nixos.idea.NixTestExecutionPolicy")
systemProperty("plugin.testDataPath", rootProject.rootDir.resolve("src/test/testData").path)
}
task<MetadataTask>("metadata") {
outputDir = layout.buildDirectory.dir("metadata")
file("version.txt", pluginVersion)
file("zipfile.txt") { buildPlugin.get().archiveFile.get().toString() }
file("latest_changelog.md") {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.MARKDOWN
)
}
}
}
generateLexer {
sourceFile = layout.projectDirectory.file("src/main/lang/Nix.flex")
targetOutputDir = lexerSource.map { it.dir("org/nixos/idea/lang") }
purgeOldFiles = true
}
generateParser {
sourceFile = layout.projectDirectory.file("src/main/lang/Nix.bnf")
targetRootOutputDir = layout.buildDirectory.dir("generated/sources/parser/java/main")
// Maybe we can remove the following properties in the future
// https://github.com/JetBrains/gradle-grammar-kit-plugin/issues/178
pathToParser = "org/nixos/idea/lang/NixParser.java"
pathToPsiRoot = "org/nixos/idea/psi"
purgeOldFiles = true
}
compileJava {
dependsOn(generateLexer)
// dependency to generateParser is implicitly detected by Gradle
}
compileKotlin {
dependsOn(generateLexer)
// dependency to generateParser is implicitly detected by Gradle
}
test {
useJUnitPlatform {
excludeTags("mock")
}
}
}