forked from ktorio/ktor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
333 lines (276 loc) · 11.7 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
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
import org.jetbrains.kotlin.konan.target.HostManager
buildscript {
/*
* These property group is used to build ktor against Kotlin compiler snapshot.
* How does it work:
* When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
* atomicfu_version, coroutines_version, serialization_version and kotlinx_io_version are overwritten by TeamCity environment.
* Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
* DO NOT change the name of these properties without adapting kotlinx.train build chain.
*/
def prop = rootProject.properties['build_snapshot_train']
ext.build_snapshot_train = prop != null && prop != ""
if (build_snapshot_train) {
ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
if (kotlin_version == null) {
throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
}
repositories {
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
configurations.classpath {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.jetbrains.kotlin') {
details.useVersion kotlin_version
}
}
}
}
repositories {
mavenLocal()
jcenter()
gradlePluginPortal()
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven {
url "https://kotlin.bintray.com/kotlin-dev"
credentials {
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
}
}
maven { url "https://dl.bintray.com/orangy/maven" }
maven { url 'https://kotlin.bintray.com/kotlinx' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "me.champeau.gradle:jmh-gradle-plugin:$jmh_plugin_version"
classpath "org.jetbrains.kotlinx:kotlinx.benchmark.gradle:$benchmarks_version"
classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$validator_version"
}
}
ext.configuredVersion = project.hasProperty("releaseVersion") ? project.releaseVersion : project.version
ext.globalM2 = "$buildDir/m2"
ext.publishLocal = project.hasProperty("publishLocal")
apply from: "gradle/experimental.gradle"
apply from: 'gradle/verifier.gradle'
/**
* `darwin` is subset of `posix`.
* Don't create `posix` and `darwin` sourceSets in single project.
*/
def platforms = ["common", "jvm", "js", "posix", "darwin"]
ext.skipPublish = ["ktor-server-benchmarks", "ktor-client-benchmarks"]
ext.nonDefaultProjectStructure = ["ktor-bom"]
def projectNeedsPlatform(project, platform) {
if (rootProject.ext.skipPublish.contains(project.name)) return platform == "jvm"
def files = project.projectDir.listFiles()
def hasPosix = files.any { it.name == "posix" }
def hasDarwin = files.any { it.name == "darwin" }
if (hasPosix && hasDarwin) return false
if (hasPosix && platform == "darwin") return false
if (hasDarwin && platform == "posix") return false
if (!hasPosix && !hasDarwin && platform == "darwin") return false
return files.any { it.name == "common" || it.name == platform }
}
def check(Object version, String libVersion, String libName) {
if (version != libVersion) {
throw new IllegalStateException("Current deploy version is $version, but $libName version is not overridden ($libVersion)")
}
}
apply from: 'gradle/compatibility.gradle'
allprojects {
group = "io.ktor"
version = configuredVersion
project.ext.hostManager = new HostManager()
if (build_snapshot_train) {
ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
println "Using Kotlin $kotlin_version for project $it"
def deployVersion = properties['DeployVersion']
if (deployVersion != null) version = deployVersion
def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
if (!skipSnapshotChecks) {
check(version, atomicfu_version, "atomicfu")
check(version, coroutines_version, "coroutines")
check(version, serialization_version, "serialization")
}
kotlin_version = rootProject.properties['kotlin_snapshot_version']
repositories {
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
repositories {
mavenLocal()
maven {
url "https://dl.bintray.com/kotlin/kotlinx/"
credentials {
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
}
}
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven {
url "https://kotlin.bintray.com/kotlin-dev"
credentials {
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
}
}
maven { url "https://dl.bintray.com/orangy/maven" }
jcenter()
}
if (rootProject.ext.nonDefaultProjectStructure.contains(project.name)) return
apply plugin: "kotlin-multiplatform"
platforms.each { platform ->
if (projectNeedsPlatform(project, platform)) {
configure([it]) {
apply from: rootProject.file("gradle/utility.gradle")
apply from: rootProject.file("gradle/${platform}.gradle")
}
}
}
if (!rootProject.ext.skipPublish.contains(project.name)) {
apply from: rootProject.file('gradle/dokka.gradle')
apply from: rootProject.file('gradle/publish.gradle')
}
configurations { testOutput }
kotlin {
configure(sourceSets) {
def srcDir = name.endsWith("Main") ? "src" : "test"
def resourcesPrefix = name.endsWith("Test") ? "test-" : ""
def platform = name[0..-5]
kotlin.srcDirs = ["$platform/$srcDir"]
resources.srcDirs = ["$platform/${resourcesPrefix}resources"]
languageSettings {
progressiveMode = true
experimentalAnnotations.each { useExperimentalAnnotation(it) }
if (project.path.startsWith(":ktor-server:ktor-server") && project.name != "ktor-server-core") {
useExperimentalAnnotation("io.ktor.server.engine.EngineAPI")
}
}
}
}
}
task rootAllTest(type: org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport) {
def rootAllTest = it
destinationDir = new File(project.buildDir, "reports/tests/rootAllTest")
allprojects {
it.afterEvaluate {
if (it.tasks.findByName("allTests") != null) {
def projectTests = it.tasks.named("allTests")
rootAllTest.addChild(projectTests)
rootAllTest.dependsOn(projectTests)
}
}
}
beforeEvaluate {
project.gradle.taskGraph.whenReady { graph ->
rootAllTest.maybeOverrideReporting(graph)
}
}
}
build.dependsOn(rootAllTest)
println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
if (build_snapshot_train) {
println "Hacking test tasks, removing stress and flaky tests"
allprojects {
tasks.withType(Test).all {
exclude '**/*ServerSocketTest*'
exclude '**/*NettyStressTest*'
exclude '**/*CIOMultithreadedTest*'
exclude '**/*testBlockingConcurrency*'
exclude '**/*testBigFile*'
exclude '**/*numberTest*'
exclude '**/*testWithPause*'
exclude '**/*WebSocketTest*'
exclude '**/*PostTest*'
exclude '**/*testCustomUrls*'
}
}
println "Manifest of kotlin-compiler-embeddable.jar"
configure(subprojects.findAll { it.name == "ktor-client" }) {
configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
def manifest = zipTree(it).matching {
include 'META-INF/MANIFEST.MF'
}.getFiles().first()
manifest.readLines().each {
println it
}
}
}
}
}
afterEvaluate {
def allCompileKotlinTasks = subprojects.collect {
it.hasProperty("compileKotlinJvm") ? [it.compileKotlinJvm] : []
}.flatten()
configure(allCompileKotlinTasks) {
kotlinOptions.freeCompilerArgs += ["-XXLanguage:+InlineClasses"]
}
task dokkaWebsite(type: dokka.getClass()) {
outputFormat = 'kotlin-website'
outputDirectory = "${rootProject.projectDir}/apidoc"
kotlinTasks { allCompileKotlinTasks }
reportUndocumented = false
}
}
allprojects {
apply plugin: "jacoco"
jacoco {
toolVersion = "0.8.5"
reportsDir = file("${buildDir}/jacoco-reports")
}
}
subprojects {
task testCoverage(type: JacocoReport, dependsOn: jvmTest) {
group = "Reporting"
description = "Generate Jacoco coverage reports."
def coverageSourceDirs = [
"common/src",
"jvm/src"
]
classDirectories.from files(fileTree(dir: "${buildDir}/classes/kotlin/jvm/"))
sourceDirectories.from files(coverageSourceDirs)
additionalSourceDirs.from files(coverageSourceDirs)
executionData.from files("${buildDir}/jacoco/jvmTest.exec")
reports {
xml.enabled true
csv.enabled false
html.enabled true
html.destination file("${buildDir}/jacoco-reports/html")
}
}
}
def findSources(sourceSet) {
return files(subprojects.findResults {
it.kotlin.sourceSets.findByName("jvmMain")?.kotlin?.srcDirs
})
}
task testCoverage(type: JacocoReport) {
group = "Reporting"
description = "Generate Jacoco coverage reports."
dependsOn subprojects.testCoverage
def coverageSourceDirs = (
findSources("commonMain") + findSources("jvmMain") + findSources("commonTest") + findSources("jvmTest")
)
def classes = files(subprojects.collect {
files(fileTree(dir: "${it.buildDir}/classes/kotlin/jvm"))
})
def samples = files(subprojects.testCoverage.executionData).findAll { it.exists() }
classDirectories.from files(classes)
sourceDirectories.from files(coverageSourceDirs)
additionalSourceDirs.from files(coverageSourceDirs)
executionData.from(samples)
reports {
xml.enabled true
csv.enabled false
html.enabled true
html.destination file("${buildDir}/jacoco-reports/html")
}
}