Skip to content

Commit

Permalink
Move compilerOptions configuration to build-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Jan 3, 2025
1 parent e9a1fce commit fb065bd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 60 deletions.
10 changes: 9 additions & 1 deletion build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions build-logic/src/main/kotlin/ktorbuild/KtorBuildExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<KotlinVersion> =
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<KotlinVersion> =
providers.gradleProperty("kotlin_language_version")
.map(KotlinVersion::fromVersion)
.orElse(DEFAULT_KOTLIN_VERSION)

/** Host operating system. */
val os: Provider<OperatingSystem> = providers.provider { buildPlatform.operatingSystem }

Expand All @@ -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
}
}
13 changes: 0 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -61,12 +60,6 @@ subprojects {

kotlin {
if (!disabledExplicitApiModeProjects.contains(project.name)) explicitApi()

compilerOptions {
languageVersion = getKotlinLanguageVersion()
apiVersion = getKotlinApiVersion()
progressiveMode = true
}
}

val skipPublish: List<String> by rootProject.extra
Expand All @@ -91,9 +84,3 @@ fun configureDokka() {
}

configureDokka()

subprojects {
tasks.withType<KotlinCompilationTask<*>>().configureEach {
configureCompilerOptions()
}
}
12 changes: 0 additions & 12 deletions buildSrc/src/main/kotlin/Compilations.kt

This file was deleted.

39 changes: 5 additions & 34 deletions buildSrc/src/main/kotlin/Train.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -67,31 +66,3 @@ private fun check(version: Any, libVersionProvider: Provider<String>, 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
}

0 comments on commit fb065bd

Please sign in to comment.