diff --git a/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts b/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts index 6cc6088435..5966eca2a9 100644 --- a/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts +++ b/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts @@ -2,6 +2,8 @@ * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ +@file:OptIn(ExperimentalKotlinGradlePluginApi::class) + import ktorbuild.internal.gradle.* import ktorbuild.internal.ktorBuild import ktorbuild.maybeNamed @@ -14,7 +16,13 @@ plugins { } kotlin { - @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + progressiveMode = true + apiVersion = ktorBuild.kotlinApiVersion + languageVersion = ktorBuild.kotlinLanguageVersion + freeCompilerArgs.addAll("-Xexpect-actual-classes") + } + applyHierarchyTemplate(KtorTargets.hierarchyTemplate) addTargets(ktorBuild.targets) diff --git a/build-logic/src/main/kotlin/ktorbuild/KtorBuildExtension.kt b/build-logic/src/main/kotlin/ktorbuild/KtorBuildExtension.kt index b8bd8063fd..ca2d2eb5a5 100644 --- a/build-logic/src/main/kotlin/ktorbuild/KtorBuildExtension.kt +++ b/build-logic/src/main/kotlin/ktorbuild/KtorBuildExtension.kt @@ -16,6 +16,7 @@ import org.gradle.kotlin.dsl.newInstance import org.gradle.kotlin.dsl.property import org.gradle.platform.BuildPlatform import org.gradle.platform.OperatingSystem +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import javax.inject.Inject @Suppress("UnstableApiUsage") @@ -69,6 +70,26 @@ abstract class KtorBuildExtension( .orElse(providers.provider { JavaVersion.current().majorVersion }) .map(JavaLanguageVersion::of) + /** + * The Kotlin API version Ktor should be compatible with. + * + * DON'T change the property name as it is used in Kotlin Libraries train. + */ + val kotlinApiVersion: Provider = + providers.gradleProperty("kotlin_api_version") + .map(KotlinVersion::fromVersion) + .orElse(DEFAULT_KOTLIN_VERSION) + + /** + * The Kotlin Language version Ktor should be compatible with. + * + * DON'T change the property name as it is used in Kotlin Libraries train. + */ + val kotlinLanguageVersion: Provider = + providers.gradleProperty("kotlin_language_version") + .map(KotlinVersion::fromVersion) + .orElse(DEFAULT_KOTLIN_VERSION) + /** Host operating system. */ val os: Provider = providers.provider { buildPlatform.operatingSystem } @@ -77,5 +98,8 @@ abstract class KtorBuildExtension( /** The default (minimal) JDK version used for building the project. */ private val DEFAULT_JDK = JavaLanguageVersion.of(8) + + /** The default (minimal) Kotlin version used as API and Language version. */ + private val DEFAULT_KOTLIN_VERSION = KotlinVersion.KOTLIN_2_0 } } diff --git a/build.gradle.kts b/build.gradle.kts index 67fad57523..ce38f4cbe0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,6 @@ * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask import org.jetbrains.kotlin.konan.target.HostManager extra["globalM2"] = "${project.file("build")}/m2" @@ -61,12 +60,6 @@ subprojects { kotlin { if (!disabledExplicitApiModeProjects.contains(project.name)) explicitApi() - - compilerOptions { - languageVersion = getKotlinLanguageVersion() - apiVersion = getKotlinApiVersion() - progressiveMode = true - } } val skipPublish: List by rootProject.extra @@ -91,9 +84,3 @@ fun configureDokka() { } configureDokka() - -subprojects { - tasks.withType>().configureEach { - configureCompilerOptions() - } -} diff --git a/buildSrc/src/main/kotlin/Compilations.kt b/buildSrc/src/main/kotlin/Compilations.kt deleted file mode 100644 index 5befd7687e..0000000000 --- a/buildSrc/src/main/kotlin/Compilations.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -import org.jetbrains.kotlin.gradle.tasks.* - -fun KotlinCompilationTask<*>.configureCompilerOptions() { - compilerOptions { - progressiveMode.set(true) - freeCompilerArgs.addAll("-Xexpect-actual-classes") - } -} diff --git a/buildSrc/src/main/kotlin/Train.kt b/buildSrc/src/main/kotlin/Train.kt index 3b3d4698ea..a91a830f33 100644 --- a/buildSrc/src/main/kotlin/Train.kt +++ b/buildSrc/src/main/kotlin/Train.kt @@ -1,12 +1,11 @@ /* * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ -import internal.* -import org.gradle.api.* -import org.gradle.api.provider.* -import org.gradle.api.tasks.testing.* -import org.gradle.kotlin.dsl.* -import org.jetbrains.kotlin.gradle.dsl.* +import internal.libs +import org.gradle.api.Project +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.withType fun Project.filterSnapshotTests() { if (!buildSnapshotTrain) return @@ -67,31 +66,3 @@ private fun check(version: Any, libVersionProvider: Provider, libName: S "Current deploy version is $version, but $libName version is not overridden ($libVersion)" } } - -private var resolvedKotlinApiVersion: KotlinVersion? = null - -fun Project.getKotlinApiVersion(): KotlinVersion = - resolvedKotlinApiVersion ?: resolveKotlinApiVersion().also { resolvedKotlinApiVersion = it } - -private fun Project.resolveKotlinApiVersion(): KotlinVersion { - val apiVersion = rootProject.findProperty("kotlin_api_version") - ?.let { KotlinVersion.fromVersion(it.toString()) } - ?: KotlinVersion.KOTLIN_2_0 - logger.info("Kotlin API version: $apiVersion") - - return apiVersion -} - -private var resolvedKotlinLanguageVersion: KotlinVersion? = null - -fun Project.getKotlinLanguageVersion(): KotlinVersion = - resolvedKotlinLanguageVersion ?: resolveKotlinLanguageVersion().also { resolvedKotlinLanguageVersion = it } - -private fun Project.resolveKotlinLanguageVersion(): KotlinVersion { - val languageVersion = rootProject.findProperty("kotlin_language_version") - ?.let { KotlinVersion.fromVersion(it.toString()) } - ?: KotlinVersion.KOTLIN_2_0 - logger.info("Kotlin language version: $languageVersion") - - return languageVersion -}