mirror of
https://github.com/jlengrand/ktor.git
synced 2026-03-10 08:31:20 +00:00
329 lines
12 KiB
Groovy
329 lines
12 KiB
Groovy
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://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"
|
|
}
|
|
}
|
|
|
|
|
|
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 = ["binary-compatibility-validator", "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)")
|
|
}
|
|
}
|
|
|
|
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*'
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|