-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
build.gradle.kts
462 lines (387 loc) · 15.9 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
@file:Suppress("HasPlatformType")
import org.gradle.internal.jvm.Jvm
import java.util.regex.Pattern.quote
description = "Kotlin Compiler"
plugins {
// HACK: java plugin makes idea import dependencies on this project as source (with empty sources however),
// this prevents reindexing of kotlin-compiler.jar after build on every change in compiler modules
`java-library`
}
val fatJarContents by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR))
}
}
val fatJarContentsStripMetadata by configurations.creating
val fatJarContentsStripServices by configurations.creating
val fatJarContentsStripVersions by configurations.creating
val compilerVersion by configurations.creating
// JPS build assumes fat jar is built from embedded configuration,
// but we can't use it in gradle build since slightly more complex processing is required like stripping metadata & services from some jars
if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
val embedded by configurations
embedded.apply {
extendsFrom(fatJarContents)
extendsFrom(fatJarContentsStripMetadata)
extendsFrom(fatJarContentsStripServices)
extendsFrom(fatJarContentsStripVersions)
extendsFrom(compilerVersion)
}
}
val api by configurations
val proguardLibraries by configurations.creating {
extendsFrom(api)
}
// Libraries to copy to the lib directory
val libraries by configurations.creating {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
}
val librariesStripVersion by configurations.creating
// Compiler plugins should be copied without `kotlin-` prefix
val compilerPlugins by configurations.creating {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
isCanBeConsumed = false
isCanBeResolved = true
}
val compilerPluginsCompat by configurations.creating {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
isCanBeConsumed = false
isCanBeResolved = true
}
val sources by configurations.creating {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
isTransitive = false
}
// contents of dist/maven directory
val distMavenContents by configurations.creating {
isTransitive = false
}
// contents of dist/common directory
val distCommonContents by configurations.creating
val distStdlibMinimalForTests by configurations.creating
val buildNumber by configurations.creating
val distJSContents by configurations.creating
val compilerBaseName = name
val outputJar = fileFrom(buildDir, "libs", "$compilerBaseName.jar")
val compilerModules: Array<String> by rootProject.extra
val distLibraryProjects = listOfNotNull(
":kotlin-annotation-processing",
":kotlin-annotation-processing-cli",
":kotlin-annotation-processing-runtime",
":kotlin-annotations-jvm",
":kotlin-ant",
":kotlin-daemon",
":kotlin-daemon-client",
// TODO: uncomment when new daemon will be put back into dist
":kotlin-imports-dumper-compiler-plugin",
":kotlin-main-kts",
":kotlin-preloader",
// Although, Kotlin compiler is compiled against reflect of an older version (which is bundled into minimal supported IDEA). We put
// SNAPSHOT reflect into the dist because we use reflect dist in user code compile classpath (see JvmArgumentsKt.configureStandardLibs).
// We can use reflect of a bigger version in Kotlin compiler runtime, because kotlin-reflect follows backwards binary compatibility
":kotlin-reflect",
":kotlin-runner",
":kotlin-script-runtime",
":kotlin-scripting-common",
":kotlin-scripting-compiler",
":kotlin-scripting-compiler-impl",
":kotlin-scripting-jvm",
":js:js.engines",
":kotlin-test:kotlin-test-junit",
":kotlin-test:kotlin-test-junit5",
":kotlin-test:kotlin-test-jvm",
":kotlin-test:kotlin-test-testng",
":libraries:tools:mutability-annotations-compat",
":plugins:android-extensions-compiler",
":plugins:jvm-abi-gen"
)
val distCompilerPluginProjects = listOf(
":kotlin-allopen-compiler-plugin",
":kotlin-android-extensions-runtime",
":plugins:parcelize:parcelize-compiler",
":plugins:parcelize:parcelize-runtime",
":kotlin-noarg-compiler-plugin",
":kotlin-sam-with-receiver-compiler-plugin",
":kotlinx-serialization-compiler-plugin",
":kotlin-lombok-compiler-plugin",
":kotlin-assignment-compiler-plugin"
)
val distCompilerPluginProjectsCompat = listOf(
":kotlinx-serialization-compiler-plugin",
)
val distSourcesProjects = listOfNotNull(
":kotlin-annotations-jvm",
":kotlin-script-runtime",
":kotlin-test:kotlin-test-js".takeIf { !kotlinBuildProperties.isInJpsBuildIdeaSync },
":kotlin-test:kotlin-test-junit",
":kotlin-test:kotlin-test-junit5",
":kotlin-test:kotlin-test-testng"
)
configurations.all {
resolutionStrategy {
preferProjectModules()
}
}
dependencies {
api(kotlinStdlib("jdk8"))
api(project(":kotlin-script-runtime"))
api(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
api(commonDependency("org.jetbrains.intellij.deps", "trove4j"))
api(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
proguardLibraries(project(":kotlin-annotations-jvm"))
compilerVersion(project(":compiler:compiler.version"))
proguardLibraries(project(":compiler:compiler.version"))
compilerModules
.filter { it != ":compiler:compiler.version" } // Version will be added directly to the final jar excluding proguard and relocation
.forEach {
fatJarContents(project(it)) { isTransitive = false }
}
libraries(kotlinStdlib("jdk8"))
if (!kotlinBuildProperties.isInJpsBuildIdeaSync) {
libraries(kotlinStdlib("js", "distLibrary"))
libraries(project(":kotlin-test:kotlin-test-js", configuration = "distLibrary"))
}
librariesStripVersion(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
librariesStripVersion(commonDependency("org.jetbrains.intellij.deps:trove4j")) { isTransitive = false }
distLibraryProjects.forEach {
libraries(project(it)) { isTransitive = false }
}
distCompilerPluginProjects.forEach {
compilerPlugins(project(it)) { isTransitive = false }
}
distCompilerPluginProjectsCompat.forEach {
compilerPluginsCompat(
project(
mapOf(
"path" to it,
"configuration" to "distCompat"
)
)
)
}
distSourcesProjects.forEach {
sources(project(it, configuration = "sources"))
}
sources(kotlinStdlib("jdk7", classifier = "sources"))
sources(kotlinStdlib("jdk8", classifier = "sources"))
if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
sources(kotlinStdlib(classifier = "sources"))
sources("org.jetbrains.kotlin:kotlin-reflect:$bootstrapKotlinVersion:sources")
} else {
sources(project(":kotlin-stdlib", configuration = "distSources"))
sources(project(":kotlin-stdlib-js", configuration = "distSources"))
sources(project(":kotlin-reflect", configuration = "sources"))
sources(project(":kotlin-test", "combinedJvmSourcesJar"))
distStdlibMinimalForTests(project(":kotlin-stdlib-jvm-minimal-for-test"))
distJSContents(project(":kotlin-stdlib-js", configuration = "distJs"))
distJSContents(project(":kotlin-test:kotlin-test-js", configuration = "distJs"))
}
distCommonContents(kotlinStdlib(suffix = "common"))
distCommonContents(kotlinStdlib(suffix = "common", classifier = "sources"))
distMavenContents(kotlinStdlib(classifier = "sources"))
buildNumber(project(":prepare:build.version", configuration = "buildVersion"))
fatJarContents(kotlinBuiltins())
fatJarContents(commonDependency("javax.inject"))
fatJarContents(commonDependency("org.jline", "jline"))
fatJarContents(commonDependency("org.fusesource.jansi", "jansi"))
fatJarContents(protobufFull())
fatJarContents(commonDependency("com.google.code.findbugs", "jsr305"))
fatJarContents(commonDependency("io.javaslang", "javaslang"))
fatJarContents(commonDependency("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm")) { isTransitive = false }
fatJarContents(intellijCore())
fatJarContents(commonDependency("org.jetbrains.intellij.deps.jna:jna")) { isTransitive = false }
fatJarContents(commonDependency("org.jetbrains.intellij.deps.jna:jna-platform")) { isTransitive = false }
fatJarContents(commonDependency("org.jetbrains.intellij.deps.fastutil:intellij-deps-fastutil")) { isTransitive = false }
fatJarContents(commonDependency("org.lz4:lz4-java")) { isTransitive = false }
fatJarContents(commonDependency("org.jetbrains.intellij.deps:asm-all")) { isTransitive = false }
fatJarContents(commonDependency("com.google.guava:guava")) { isTransitive = false }
//Gson is needed for kotlin-build-statistics. Build statistics could be enabled for JPS and Gradle builds. Gson will come from inteliij or KGP.
proguardLibraries(commonDependency("com.google.code.gson:gson")) { isTransitive = false}
fatJarContentsStripServices(commonDependency("com.fasterxml:aalto-xml")) { isTransitive = false }
fatJarContents(commonDependency("org.codehaus.woodstox:stax2-api")) { isTransitive = false }
fatJarContentsStripServices(jpsModel()) { isTransitive = false }
fatJarContentsStripServices(jpsModelImpl()) { isTransitive = false }
fatJarContentsStripMetadata(commonDependency("oro:oro")) { isTransitive = false }
fatJarContentsStripMetadata(commonDependency("org.jetbrains.intellij.deps:jdom")) { isTransitive = false }
fatJarContentsStripMetadata(commonDependency("org.jetbrains.intellij.deps:log4j")) { isTransitive = false }
fatJarContentsStripVersions(commonDependency("one.util:streamex")) { isTransitive = false }
}
publish()
val packCompiler by task<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
destinationDirectory.set(File(buildDir, "libs"))
archiveClassifier.set("before-proguard")
dependsOn(fatJarContents)
from {
fatJarContents.map(::zipTree)
}
dependsOn(fatJarContentsStripServices)
from {
fatJarContentsStripServices.files.map {
zipTree(it).matching { exclude("META-INF/services/**") }
}
}
dependsOn(fatJarContentsStripMetadata)
from {
fatJarContentsStripMetadata.files.map {
zipTree(it).matching { exclude("META-INF/jb/**", "META-INF/LICENSE") }
}
}
dependsOn(fatJarContentsStripVersions)
from {
fatJarContentsStripVersions.files.map {
zipTree(it).matching { exclude("META-INF/versions/**") }
}
}
}
val proguard by task<CacheableProguardTask> {
dependsOn(packCompiler)
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_1_8))
configuration("$projectDir/compiler.pro")
injars(
mapOf("filter" to """
!org/apache/log4j/jmx/Agent*,
!org/apache/log4j/net/JMS*,
!org/apache/log4j/net/SMTP*,
!org/apache/log4j/or/jms/MessageRenderer*,
!org/jdom/xpath/Jaxen*,
!org/jline/builtins/ssh/**,
!org/mozilla/javascript/xml/impl/xmlbeans/**,
!net/sf/cglib/**,
!META-INF/maven**,
**.class,**.properties,**.kt,**.kotlin_*,**.jnilib,**.so,**.dll,**.txt,**.caps,
META-INF/services/**,META-INF/native/**,META-INF/extensions/**,META-INF/MANIFEST.MF,
messages/**""".trimIndent()),
provider { packCompiler.get().outputs.files.singleFile }
)
outjars(fileFrom(buildDir, "libs", "$compilerBaseName-after-proguard.jar"))
libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraries)
libraryjars(
files(
javaLauncher.map {
firstFromJavaHomeThatExists(
"jre/lib/rt.jar",
"../Classes/classes.jar",
jdkHome = it.metadata.installationPath.asFile
)
},
javaLauncher.map {
firstFromJavaHomeThatExists(
"jre/lib/jsse.jar",
"../Classes/jsse.jar",
jdkHome = it.metadata.installationPath.asFile
)
},
javaLauncher.map {
Jvm.forHome(it.metadata.installationPath.asFile).toolsJar
}
)
)
printconfiguration("$buildDir/compiler.pro.dump")
}
val pack = if (kotlinBuildProperties.proguard) proguard else packCompiler
val distDir: String by rootProject.extra
val jar = runtimeJar {
dependsOn(pack)
dependsOn(compilerVersion)
from {
zipTree(pack.get().singleOutputFile())
}
from {
compilerVersion.map(::zipTree)
}
manifest.attributes["Class-Path"] = compilerManifestClassPath
manifest.attributes["Main-Class"] = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
}
sourcesJar {
from {
compilerModules.map {
project(it).mainSourceSet.allSource
}
}
dependsOn(":compiler:fir:checkers:generateCheckersComponents", ":compiler:ir.tree:generateTree")
}
javadocJar()
val distKotlinc = distTask<Sync>("distKotlinc") {
destinationDir = File("$distDir/kotlinc")
from(buildNumber)
val binFiles = files("$rootDir/compiler/cli/bin")
into("bin") {
from(binFiles)
}
val licenseFiles = files("$rootDir/license")
into("license") {
from(licenseFiles)
}
val compilerBaseName = compilerBaseName
val jarFiles = files(jar)
val librariesFiles = files(libraries)
val librariesStripVersionFiles = files(librariesStripVersion)
val sourcesFiles = files(sources)
val compilerPluginsFiles = files(compilerPlugins)
val compilerPluginsCompatFiles = files(compilerPluginsCompat)
into("lib") {
from(jarFiles) { rename { "$compilerBaseName.jar" } }
from(librariesFiles)
from(librariesStripVersionFiles) {
rename {
it.replace(Regex("-\\d.*\\.jar\$"), ".jar")
}
}
from(sourcesFiles)
from(compilerPluginsFiles) {
rename {
// We want to migrate all compiler plugin in 'dist' to have 'kotlin-' prefix
// 'kotlin-serialization-compiler-plugin' is a new jar and should have such prefix from the start
if (!it.startsWith("kotlin-serialization")) {
it.removePrefix("kotlin-")
} else {
it
}
}
}
from(compilerPluginsCompatFiles) {
rename { it.removePrefix("kotlin-") }
}
}
}
val distCommon = distTask<Sync>("distCommon") {
destinationDir = File("$distDir/common")
from(distCommonContents)
}
val distMaven = distTask<Sync>("distMaven") {
destinationDir = File("$distDir/maven")
from(distMavenContents)
}
val distJs = distTask<Sync>("distJs") {
destinationDir = File("$distDir/js")
from(distJSContents)
}
val compilerZipSbomName = "kotlin-compiler-zip"
val compilerZipSbom = configureSbom(
moduleName = compilerZipSbomName,
gradleConfigurations = setOf("runtimeClasspath", libraries.name, librariesStripVersion.name, compilerPlugins.name)
)
distTask<Copy>("dist") {
destinationDir = File(distDir)
dependsOn(distKotlinc)
dependsOn(distCommon)
dependsOn(distMaven)
dependsOn(distJs)
from(buildNumber)
from(distStdlibMinimalForTests)
from(compilerZipSbom.artifacts.files) {
rename("$compilerZipSbomName.spdx.json", "${project.name}-${project.version}.spdx.json")
}
}
inline fun <reified T : AbstractCopyTask> Project.distTask(
name: String,
crossinline block: T.() -> Unit
) = tasks.register<T>(name) {
duplicatesStrategy = DuplicatesStrategy.FAIL
rename(quote("-$version"), "")
rename(quote("-$bootstrapKotlinVersion"), "")
block()
}