-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
build.gradle
229 lines (208 loc) · 9.27 KB
/
build.gradle
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
import static org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9
//file:noinspection GrMethodMayBeStatic // Disable because it has false positives
//file:noinspection GroovyAssignabilityCheck // Disable because it has false positives
plugins {
id 'org.jetbrains.intellij.platform' version '2.0.1'
id 'org.jetbrains.kotlin.jvm' version '1.9.24'
id 'java'
id 'groovy'
}
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}
// Should match Kotlin version bundled with IntelliJ (see https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library)
// If the version is older, it will still work in IJ but is likely to be incompatible with Kotlin plugin which is often one version ahead.
ext.kotlinVersion = "1.9.24"
// Must match Groovy version bundled with IntelliJ (see IJ/Contents/lib/groovy.jar/META-INF/org.codehaus.groovy.runtime.ExtensionModule)
ext.groovyVersion = "3.0.19"
intellijPlatform {
projectName = "LivePlugin"
instrumentCode = false // Not needed for LivePlugin (true by default in gradle plugin which is a bad idea)
buildSearchableOptions = false // Disable because it takes a long time and the plugin doesn't need it
pluginConfiguration {
ideaVersion {
// TODO doesn't work with org.jetbrains.intellij.platform 🙄
untilBuild = null // Disable patching plugin.xml because "until" version is too restrictive (it's better to keep it open-ended).
}
}
}
dependencies {
intellijPlatform {
// For available IDE versions see "com.jetbrains.intellij.idea" in
// https://www.jetbrains.com/intellij-repository/releases and https://www.jetbrains.com/intellij-repository/snapshots
intellijIdeaCommunity(
// "2024.1.1" // Compatibility with IJ 2024.1.1
"2024.2.0.1" // Compatibility with IJ 2024.2.0.1
)
bundledPlugin "com.intellij.java"
bundledPlugin "org.intellij.groovy"
bundledPlugin "org.jetbrains.kotlin"
bundledPlugin "Git4Idea"
bundledPlugin "org.jetbrains.plugins.github"
bundledPlugin "JUnit"
}
implementation project(":kotlin-compiler-wrapper")
// Bundle Kotlin compiler and stdlib with LivePlugin because they are not always included into IDEs
// and because Kotlin jars in IDE are likely to be updated, potentially breaking liveplugins,
// so it should be more reliable to have a particular version of Kotlin jars inside LivePlugin.
runtimeOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion"
runtimeOnly "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlinVersion"
runtimeOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
// Explicit Groovy dependency because even though Groovy is bundled with IJ,
// it's not picked up by Groovy compiler in the latest versions.
compileOnly "org.codehaus.groovy:groovy-all:$groovyVersion"
testCompileOnly "org.codehaus.groovy:groovy-all:$groovyVersion"
implementation "org.http4k:http4k-core:5.20.0.0"
implementation("org.http4k:http4k-client-okhttp:5.20.0.0") {
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk8"
}
testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.1"
testImplementation "org.junit.platform:junit-platform-engine:1.9.0"
}
"Move kotlin compiler jars from plugin classpath into a separate folder so that there are no conflicts between kotlin and intellij classes"()
"Add source files to compiler output so that LivePlugin source code is available for navigation at runtime"()
'Copy GDSL file into standardDsls folder'()
sourceSets {
// Keep Groovy and Kotlin API source code in separate source sets, otherwise
// compilation fails because of inter-dependencies between Kotlin and Groovy files which confuse compiler,
// even though overall dependencies are unidirectional: pluginApiKotlin -> pluginApiGroovy -> main.
main {
java { srcDir "src/main" }
resources { srcDir "resources" }
resources { srcDir "plugin-examples" }
}
pluginApiGroovy {
groovy { srcDir "src/plugin-api-groovy" }
compileClasspath = main.output +
configurations.compileClasspath + configurations.runtimeClasspath +
configurations.pluginApiGroovyCompileClasspath + configurations.pluginApiGroovyRuntimeClasspath
}
pluginApiKotlin {
kotlin { srcDir "src/plugin-api-kotlin" }
compileClasspath = main.output + pluginApiGroovy.output +
configurations.compileClasspath + configurations.pluginApiKotlinCompileClasspath
}
test {
groovy { srcDir "src/test" }
kotlin { srcDir "src/test" }
compileClasspath = main.output + pluginApiGroovy.output + pluginApiKotlin.output +
configurations.testCompileClasspath + configurations.pluginApiGroovyCompileClasspath
runtimeClasspath = test.output + main.output + pluginApiGroovy.output + pluginApiKotlin.output +
configurations.testRuntimeClasspath + configurations.pluginApiGroovyRuntimeClasspath
}
}
kotlin {
jvmToolchain(21)
}
compileKotlin {
compilerOptions {
apiVersion.set(KOTLIN_1_9)
languageVersion.set(KOTLIN_1_9)
freeCompilerArgs = ["-Xjvm-default=all"] // Added for LivePluginKotlinScriptProvider
}
}
jar {
from sourceSets.pluginApiGroovy.output, sourceSets.pluginApiKotlin.output
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.register('validateLivePluginZip') {
doLast {
def pluginZip = zipTree("build/distributions/LivePlugin.zip")
def pluginZipFiles = pluginZip.files.collect { it.path.replaceFirst(".*[/\\\\]zip_.*?[/\\\\]", "").replace("\\", "/") }
def kotlinCompilerAndItsTransitiveDependencies = [
"LivePlugin/kotlin-compiler/annotations-13.0.jar",
"LivePlugin/kotlin-compiler/kotlin-compiler-embeddable-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-compiler-wrapper.jar",
"LivePlugin/kotlin-compiler/kotlin-daemon-embeddable-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-reflect-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-script-runtime-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-common-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-compiler-embeddable-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-compiler-impl-embeddable-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-jvm-1.9.24.jar",
"LivePlugin/kotlin-compiler/kotlin-stdlib-1.9.24.jar",
"LivePlugin/kotlin-compiler/trove4j-1.0.20200330.jar",
"LivePlugin/lib/http4k-client-okhttp-5.20.0.0.jar",
"LivePlugin/lib/http4k-core-5.20.0.0.jar",
"LivePlugin/lib/http4k-realtime-core-5.20.0.0.jar",
"LivePlugin/lib/okhttp-4.12.0.jar",
"LivePlugin/lib/okio-jvm-3.6.0.jar",
]
def expectedLivePluginJars = [
"LivePlugin/lib/live-plugin.jar",
"LivePlugin/lib/standardDsls/livePluginCompletions.gdsl",
]
expectToBeEqual(pluginZipFiles.toSorted(), (expectedLivePluginJars + kotlinCompilerAndItsTransitiveDependencies).toSorted())
def livePluginJar = zipTree(pluginZip.files.find { it.name == "live-plugin.jar" })
def livePluginJarFiles = livePluginJar.files.collect { it.path.replaceFirst(".*[/\\\\]zip_.*?[/\\\\]", "").replace("\\", "/") }.toSet()
expectToContain(livePluginJarFiles, [
"liveplugin/implementation/LivePlugin.class",
"liveplugin/PluginUtil.class",
"liveplugin/PluginUtil.groovy",
"liveplugin/Plugin_utilKt.class",
"liveplugin/plugin-util.kt",
"groovy/default-plugin.groovy",
"kotlin/default-plugin.kts",
"META-INF/plugin.xml",
].toSet())
}
}
buildPlugin.finalizedBy(validateLivePluginZip)
static expectToContain(Set actual, Set expected) {
if (!actual.containsAll(expected)) {
throw new GradleException(
"Didn't contain expected:\n" +
(expected - actual).join("\n") + "\n"
)
}
}
static expectToBeEqual(Collection actual, Collection expected) {
if (actual != expected) {
throw new GradleException(
"Expected:\n" +
expected.join("\n") + "\n" +
"but was:\n" +
actual.join("\n")
)
}
}
def "Add source files to compiler output so that LivePlugin source code is available for navigation at runtime"() {
compileJava.doLast {
def classesFolder = project.tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME).get().destinationDir
ant.copy(toDir: classesFolder.absolutePath, overwrite: true) {
ant.fileset(dir: "./src/plugin-api-groovy", includes: "**/*")
ant.fileset(dir: "./src/plugin-api-kotlin", includes: "**/*")
ant.fileset(dir: "./src/main", includes: "**/LivePluginScript.kt")
}
}
}
def "Move kotlin compiler jars from plugin classpath into a separate folder so that there are no conflicts between kotlin and intellij classes"() {
prepareSandbox.doLast {
new File("build/idea-sandbox/IC-2024.2.0.1/plugins/LivePlugin/lib")
.listFiles().toList()
.findAll {
(it.name.startsWith("kotlin-") || it.name.startsWith("jna-") || it.name.startsWith("annotations-") || it.name.startsWith("trove4j-")) &&
it.name.endsWith(".jar") && it.name != "LivePlugin.jar"
}
.each {
ant.move(
file: "build/idea-sandbox/IC-2024.2.0.1/plugins/LivePlugin/lib/${it.name}",
tofile: "build/idea-sandbox/IC-2024.2.0.1/plugins/LivePlugin/kotlin-compiler/${it.name}"
)
}
}
}
def 'Copy GDSL file into standardDsls folder'() {
prepareSandbox.doLast {
def resourcesFolder = project.tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME).get().destinationDir
ant.copy(
file: resourcesFolder.absolutePath + "/liveplugin/livePluginCompletions.gdsl",
tofile: "build/idea-sandbox/IC-2024.2.0.1/plugins/LivePlugin/lib/standardDsls/livePluginCompletions.gdsl",
quiet: true
)
}
}