-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
build.gradle
233 lines (212 loc) · 8.89 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
230
231
232
233
//file:noinspection GrMethodMayBeStatic // Disable because it has false positives
//file:noinspection GroovyAssignabilityCheck // Disable because it has false positives
import static org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
plugins {
id 'org.jetbrains.intellij.platform' version '2.0.1'
id 'org.jetbrains.kotlin.jvm' version '2.0.10'
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.
//
// Not upgrading to 2.0.21 because it fails with:
// Caused by: java.lang.RuntimeException: Could not find installation home path. Please reinstall the software.
// at org.jetbrains.kotlin.com.intellij.openapi.application.PathManager.getHomePath(PathManager.java:98)
ext.kotlinVersion = "2.0.10"
// 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"
// 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
// (👇version with Kotlin 2.1 and changes in PluginClassLoader)
ext.ideVersion = "243.21155.17-EAP-SNAPSHOT"
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 {
untilBuild = provider { null } // Disable patching plugin.xml because "until" version is too restrictive (it's better to keep it open-ended)
}
}
}
dependencies {
intellijPlatform {
intellijIdeaCommunity(ideVersion, false)
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.28.1.0"
implementation("org.http4k:http4k-client-okhttp:5.28.1.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"("build/idea-sandbox/IC-2024.3")
"Add source files to compiler output so that LivePlugin source code is available for navigation at runtime"()
'Copy GDSL file into standardDsls folder'("build/idea-sandbox/IC-2024.3")
sourceSets {
main {
// Keep Kotlin and Groovy API source code in separate folders for clarity.
java { srcDir "src/main" }
groovy { srcDir "src/plugin-api-groovy" }
kotlin { srcDir "src/plugin-api-kotlin" }
resources { srcDir "resources" }
resources { srcDir "plugin-examples" }
}
test {
groovy { srcDir "src/test" }
kotlin { srcDir "src/test" }
}
}
// Make Groovy compilation depend on Kotlin as described here
// https://docs.gradle.org/current/userguide/building_java_projects.html#sub:compile_deps_jvm_lang
tasks.named('compileGroovy') {
classpath += files(sourceSets.main.kotlin.classesDirectory)
}
kotlin {
jvmToolchain(17)
}
compileKotlin {
compilerOptions {
apiVersion.set(KOTLIN_2_0)
languageVersion.set(KOTLIN_2_0)
freeCompilerArgs = [
"-Xjvm-default=all", // Added for LivePluginKotlinScriptProvider
"-Xskip-prerelease-check"
]
}
}
jar {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks {
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
hidden.set(true)
}
}
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-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-compiler-wrapper.jar",
"LivePlugin/kotlin-compiler/kotlin-daemon-embeddable-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-reflect-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-script-runtime-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-common-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-compiler-embeddable-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-compiler-impl-embeddable-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-jvm-2.0.10.jar",
"LivePlugin/kotlin-compiler/kotlin-stdlib-2.0.10.jar",
"LivePlugin/kotlin-compiler/trove4j-1.0.20200330.jar",
"LivePlugin/lib/http4k-client-okhttp-5.28.1.0.jar",
"LivePlugin/lib/http4k-core-5.28.1.0.jar",
"LivePlugin/lib/http4k-realtime-core-5.28.1.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"(idePath) {
prepareSandbox.doLast {
new File("$idePath/plugins/LivePlugin/lib")
.listFiles().toList()
.findAll { it.name.endsWith(".jar") && it.name != "LivePlugin.jar" }
.findAll {
it.name.startsWith("kotlin-")
|| it.name.startsWith("jna-")
|| it.name.startsWith("annotations-")
|| it.name.startsWith("trove4j-")
|| it.name.startsWith("kotlinx-")
}
.each {
ant.move(
file: "$idePath/plugins/LivePlugin/lib/${it.name}",
tofile: "$idePath/plugins/LivePlugin/kotlin-compiler/${it.name}"
)
}
}
}
def 'Copy GDSL file into standardDsls folder'(idePath) {
prepareSandbox.doLast {
def resourcesFolder = project.tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME).get().destinationDir
ant.copy(
file: resourcesFolder.absolutePath + "/liveplugin/livePluginCompletions.gdsl",
tofile: "$idePath/plugins/LivePlugin/lib/standardDsls/livePluginCompletions.gdsl",
quiet: true
)
}
}