forked from dkandalov/live-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
254 lines (231 loc) · 10.6 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://pkg.sourceplus.plus/sourceplusplus/protocol" }
}
}
plugins {
id "org.jetbrains.intellij"
id "org.jetbrains.kotlin.jvm"
}
apply plugin:"java"
apply plugin:"groovy"
apply plugin:"idea"
apply plugin:"org.jetbrains.intellij"
archivesBaseName = "LivePlugin"
repositories {
mavenCentral()
}
// 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.8.22"
// Must match Groovy version bundled with IntelliJ (see IJ/Contents/lib/groovy.jar/META-INF/org.codehaus.groovy.runtime.ExtensionModule)
ext.groovyVersion = "3.0.13"
intellij {
// To find available IDE versions see https://www.jetbrains.com/intellij-repository/releases
// and https://www.jetbrains.com/intellij-repository/snapshots
version = System.getenv().getOrDefault("IJ_VERSION",
// "221.5080.210" // Compatibility with IJ 2022.1 (Groovy 3, Kotlin 1.6, changes in PluginClassLoader https://github.com/dkandalov/live-plugin/issues/123)
"2023.2.2" // Compatibility with IJ 2023.1 (Kotlin 1.8, changes in PluginClassLoader https://github.com/dkandalov/live-plugin/issues/155)
)
pluginName = "LivePlugin"
downloadSources = true
updateSinceUntilBuild = false // Disable patching plugin.xml because "until" version is too restrictive (it's better to keep it open-ended).
plugins = [
"java",
"Groovy",
"Kotlin",
"junit",
// "com.intellij.dev"
]
}
buildSearchableOptions.enabled = false // Disable because LivePlugin doesn't need it, it takes a long time and it was failing at some point https://youtrack.jetbrains.com/issue/KTIJ-782.
runIde.jbrVariant.set("jcef") // JVM with Java Chromium Embedded Framework because why not (see also https://github.com/JetBrains/gradle-intellij-plugin#running-dsl)
var protocolVersion = project.properties["protocolVersion"] as String ?: projectVersion
dependencies {
if (findProject(":interfaces:jetbrains") != null) {
compileOnly project(":interfaces:jetbrains:commander:kotlin-compiler-wrapper")
compileOnly project(":interfaces:jetbrains:core")
compileOnly project(":interfaces:jetbrains:insight")
compileOnly project(":interfaces:jetbrains:marker")
compileOnly project(":protocol")
} else {
compileOnly project(":core")
compileOnly project(":insight")
compileOnly project(":marker")
compileOnly("plus.sourceplus:protocol:$protocolVersion")
}
compileOnly("io.vertx:vertx-core:$vertxVersion")
compileOnly("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion")
compileOnly("org.jooq:joor:$joorVersion")
// 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}"
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" }
}
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
}
}
tasks.withType(JavaCompile).configureEach {
sourceCompatibility = "17"
targetCompatibility = "17"
}
// Not using KotlinCompile import because of https://youtrack.jetbrains.com/issue/IDEA-201732
//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
sourceCompatibility = "17"
targetCompatibility = "17"
kotlinOptions {
sourceCompatibility = "17"
targetCompatibility = "17"
jvmTarget = "17"
apiVersion = "1.8"
languageVersion = "1.8"
freeCompilerArgs = ["-Xjvm-default=all"] // Added for LivePluginKotlinScriptProvider
}
}
jar {
from sourceSets.pluginApiGroovy.output, sourceSets.pluginApiKotlin.output
}
tasks.register('validateLivePluginZip') {
doLast {
def pluginZip = zipTree("build/distributions/LivePlugin.zip")
def pluginZipFiles = pluginZip.files.collect { it.path.replaceFirst(".*[/\\\\]LivePlugin.zip.*?[/\\\\]", "").replace("\\", "/") }
def kotlinCompilerAndItsTransitiveDependencies = [
"LivePlugin/kotlin-compiler/annotations-13.0.jar",
"LivePlugin/kotlin-compiler/jna-5.6.0.jar",
"LivePlugin/kotlin-compiler/kotlin-compiler-embeddable-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-compiler-wrapper.jar",
"LivePlugin/kotlin-compiler/kotlin-daemon-embeddable-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-reflect-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-script-runtime-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-common-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-compiler-embeddable-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-compiler-impl-embeddable-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-scripting-jvm-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-stdlib-1.8.22.jar",
"LivePlugin/kotlin-compiler/kotlin-stdlib-common-1.8.22.jar",
"LivePlugin/kotlin-compiler/trove4j-1.0.20200330.jar",
"LivePlugin/lib/http4k-client-okhttp-4.26.0.0.jar",
"LivePlugin/lib/http4k-core-4.26.0.0.jar",
"LivePlugin/lib/okhttp-4.9.3.jar",
"LivePlugin/lib/okio-jvm-2.8.0.jar"
]
def expectedLivePluginJars = [
"LivePlugin/lib/LivePlugin.jar",
"LivePlugin/lib/standardDsls/livePluginCompletions.gdsl",
]
expectToBeEqual(pluginZipFiles.toSorted(), (expectedLivePluginJars + kotlinCompilerAndItsTransitiveDependencies).toSorted())
def livePluginJar = zipTree(pluginZip.files.find { it.name == "LivePlugin.jar" })
def livePluginJarFiles = livePluginJar.files.collect { it.path.replaceFirst(".*[/\\\\]LivePlugin.jar.*?[/\\\\]", "").replace("\\", "/") }.toSet()
expectToContain(livePluginJarFiles, [
"liveplugin/implementation/LivePlugin.class",
"liveplugin/PluginUtil.class",
"liveplugin/PluginUtil.groovy",
"liveplugin/Plugin_utilKt.class",
"liveplugin/plugin-util.kt",
"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/plugins/interface-jetbrains/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/plugins/interface-jetbrains/lib/${it.name}",
// tofile: "build/idea-sandbox/plugins/interface-jetbrains/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/plugins/LivePlugin/lib/standardDsls/livePluginCompletions.gdsl",
quiet: true
)
}
}
project.tasks.findByName("listProductsReleases").enabled = false
project.tasks.findByName("runIde").enabled = false
project.tasks.findByName("prepareSandbox").enabled = false
project.tasks.findByName("buildPlugin").enabled = false
project.tasks.findByName("verifyPlugin").enabled = false
project.tasks.findByName("publishPlugin").enabled = false
project.tasks.findByName("validateLivePluginZip").enabled = false
project.tasks.findByName("spotlessKotlinCheck").enabled = false