Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K1 dev warning as errors cherry-pick #2950

Merged
merged 9 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ tasks.assemble {
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}

kotlinOptions {
if (overriddenLanguageVersion != null) {
languageVersion = overriddenLanguageVersion
freeCompilerArgs += "-Xsuppress-version-warnings"
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ publishing {
forEach { pub ->
pub as DefaultMavenPublication
pub.unsetModuleDescriptorGenerator()
tasks.matching { it.name == "generateMetadataFileFor${pub.name.capitalize()}Publication" }.all {
onlyIf { false }

tasks.configureEach {
if (name == "generateMetadataFileFor${pub.name.capitalizeCompat()}Publication") {
onlyIf { false }
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import kotlinx.validation.*
import org.jetbrains.dokka.gradle.*
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion

plugins {
base
Expand Down Expand Up @@ -157,10 +158,8 @@ tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstall
args.add("--ignore-engines")
}

// == compiler version setup ==
gradle.taskGraph.whenReady {
println("Using Kotlin compiler version: ${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}")
}
// == KGP version setup ==
logger.warn("Project is using Kotlin Gradle plugin version: ${project.getKotlinPluginVersion()}")

// == projects lists and flags ==
// getters are required because of variable lazy initialization in Gradle
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ repositories {
mavenLocal()
}

kotlin {
compilerOptions {
allWarningsAsErrors = true
}
}

dependencies {
implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.kover)
Expand Down
1 change: 1 addition & 0 deletions buildSrc/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.kotlin.dsl.allWarningsAsErrors=true
61 changes: 38 additions & 23 deletions buildSrc/src/main/kotlin/Java9Modularity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.*
import org.jetbrains.kotlin.gradle.targets.jvm.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -27,6 +26,13 @@ import kotlin.reflect.*
import kotlin.reflect.full.*

object Java9Modularity {
private val KotlinProjectExtension.targets: Iterable<KotlinTarget>
get() = when (this) {
is KotlinSingleTargetExtension<*> -> listOf(this.target)
is KotlinMultiplatformExtension -> targets
else -> error("Unexpected 'kotlin' extension $this")
}


@JvmStatic
@JvmOverloads
Expand All @@ -49,16 +55,19 @@ object Java9Modularity {
}

target.compilations.forEach { compilation ->
val compileKotlinTask = compilation.compileKotlinTask as KotlinCompile
@Suppress("UNCHECKED_CAST")
val compileKotlinTask = compilation.compileTaskProvider as TaskProvider<KotlinCompile>
val defaultSourceSet = compilation.defaultSourceSet

// derive the names of the source set and compile module task
val sourceSetName = defaultSourceSet.name + "Module"

kotlin.sourceSets.create(sourceSetName) {
val sourceFile = this.kotlin.find { it.name == "module-info.java" }
val targetDirectory = compileKotlinTask.destinationDirectory.map {
it.dir("../${it.asFile.name}Module")
val targetDirectory = compileKotlinTask.flatMap { task ->
task.destinationDirectory.map {
it.dir("../${it.asFile.name}Module")
}
}

// only configure the compilation if necessary
Expand Down Expand Up @@ -109,37 +118,38 @@ object Java9Modularity {
* but it currently won't compile to a module-info.class file.
*/
private fun Project.registerVerifyModuleTask(
compileTask: KotlinCompile,
compileTask: TaskProvider<KotlinCompile>,
sourceFile: File
): TaskProvider<out KotlinJvmCompile> {
apply<KotlinApiPlugin>()
val verifyModuleTaskName = "verify${compileTask.name.removePrefix("compile").capitalize()}Module"
val verifyModuleTaskName = "verify${compileTask.name.removePrefix("compile").capitalizeCompat()}Module"
// work-around for https://youtrack.jetbrains.com/issue/KT-60542
val kotlinApiPlugin = plugins.getPlugin(KotlinApiPlugin::class)
val verifyModuleTask = kotlinApiPlugin.registerKotlinJvmCompileTask(
verifyModuleTaskName,
compileTask.compilerOptions.moduleName.get()
compilerOptions = compileTask.get().compilerOptions,
explicitApiMode = provider { ExplicitApiMode.Disabled }
)
verifyModuleTask {
group = VERIFICATION_GROUP
description = "Verify Kotlin sources for JPMS problems"
libraries.from(compileTask.libraries)
source(compileTask.sources)
source(compileTask.javaSources)
libraries.from(compileTask.map { it.libraries })
source(compileTask.map { it.sources })
source(compileTask.map { it.javaSources })
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
@Suppress("INVISIBLE_MEMBER")
source(compileTask.scriptSources)
source(compileTask.map {
@Suppress("INVISIBLE_MEMBER")
it.scriptSources
})
source(sourceFile)
destinationDirectory.set(temporaryDir)
multiPlatformEnabled.set(compileTask.multiPlatformEnabled)
multiPlatformEnabled.set(compileTask.get().multiPlatformEnabled)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_9)
// To support LV override when set in aggregate builds
languageVersion.set(compileTask.compilerOptions.languageVersion)
freeCompilerArgs.addAll(
listOf("-Xjdk-release=9", "-Xsuppress-version-warnings", "-Xexpect-actual-classes")
)
optIn.addAll(compileTask.kotlinOptions.options.optIn)
optIn.addAll(compileTask.flatMap { it.compilerOptions.optIn })
}
// work-around for https://youtrack.jetbrains.com/issue/KT-60583
inputs.files(
Expand All @@ -160,18 +170,21 @@ object Java9Modularity {
.declaredMemberProperties
.find { it.name == "ownModuleName" }
?.get(this) as? Property<String>
ownModuleNameProp?.set(compileTask.kotlinOptions.moduleName)
ownModuleNameProp?.set(compileTask.flatMap { it.compilerOptions.moduleName})
}

val taskKotlinLanguageVersion = compilerOptions.languageVersion.orElse(KotlinVersion.DEFAULT)
@OptIn(InternalKotlinGradlePluginApi::class)
if (taskKotlinLanguageVersion.get() < KotlinVersion.KOTLIN_2_0) {
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
@Suppress("INVISIBLE_MEMBER")
commonSourceSet.from(compileTask.commonSourceSet)
commonSourceSet.from(compileTask.map {
@Suppress("INVISIBLE_MEMBER")
it.commonSourceSet
})
} else {
multiplatformStructure.refinesEdges.set(compileTask.multiplatformStructure.refinesEdges)
multiplatformStructure.fragments.set(compileTask.multiplatformStructure.fragments)
multiplatformStructure.refinesEdges.set(compileTask.flatMap { it.multiplatformStructure.refinesEdges })
multiplatformStructure.fragments.set(compileTask.flatMap { it.multiplatformStructure.fragments })
}
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
// and work-around for https://youtrack.jetbrains.com/issue/KT-60582
Expand All @@ -181,7 +194,7 @@ object Java9Modularity {
}

private fun Project.registerCompileModuleTask(
compileTask: KotlinCompile,
compileTask: TaskProvider<KotlinCompile>,
sourceFile: File,
targetDirectory: Provider<out Directory>
) = tasks.register("${compileTask.name}Module", JavaCompile::class) {
Expand All @@ -201,10 +214,12 @@ object Java9Modularity {

options.compilerArgumentProviders.add(object : CommandLineArgumentProvider {
@get:CompileClasspath
val compileClasspath = compileTask.libraries
val compileClasspath = objects.fileCollection().from(
compileTask.map { it.libraries }
)

@get:CompileClasspath
val compiledClasses = compileTask.destinationDirectory
val compiledClasses = compileTask.flatMap { it.destinationDirectory }

@get:Input
val moduleName = sourceFile
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/dokka-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import org.jetbrains.dokka.gradle.*
import java.net.URL
import java.net.URI

/*
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Expand Down Expand Up @@ -71,7 +71,7 @@ tasks.withType<DokkaTaskPartial>().named("dokkaHtmlPartial") {
sourceLink {
localDirectory.set(rootDir)

remoteUrl.set(URL("https://github.com/Kotlin/kotlinx.serialization/tree/master"))
remoteUrl.set(URI("https://github.com/Kotlin/kotlinx.serialization/tree/master").toURL())
remoteLineSuffix.set("#L")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ kotlin {
watchosDeviceArm64()

// Deprecated, but not removed
@Suppress("DEPRECATION")
linuxArm32Hfp()
}

Expand Down
51 changes: 31 additions & 20 deletions buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:OptIn(ExperimentalWasmDsl::class)

import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.testing.*
import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.testing.*
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
Expand All @@ -34,11 +38,14 @@ kotlin {
explicitApi()

jvm {
@Suppress("DEPRECATION") // Migrate on Kotlin 2.1.20 update
withJava()
compilations.configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xjdk-release=1.8"
compileTaskProvider.configure {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.add("-Xjdk-release=1.8")
}
}
}
}
Expand All @@ -52,18 +59,22 @@ kotlin {
}
}
compilations.matching { it.name == "main" || it.name == "test" }.configureEach {
kotlinOptions {
sourceMap = true
moduleKind = "umd"
compileTaskProvider.configure {
compilerOptions {
sourceMap = true
moduleName = "umd"
}
}
}
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}

if (!isOkIoOrFormatTests) {
@OptIn(ExperimentalWasmDsl::class)
wasmWasi {
nodejs()
}
Expand Down Expand Up @@ -164,18 +175,18 @@ kotlin {
}
}

targets.all {
compilations.all {
kotlinOptions {
if (overriddenLanguageVersion != null) {
languageVersion = overriddenLanguageVersion
freeCompilerArgs += "-Xsuppress-version-warnings"
}
freeCompilerArgs += "-Xexpect-actual-classes"
}
compilerOptions {
if (overriddenLanguageVersion != null) {
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
compilations["main"].kotlinOptions {
allWarningsAsErrors = true
freeCompilerArgs.add("-Xexpect-actual-classes")
}


targets.all {
compilations["main"].compileTaskProvider.configure {
compilerOptions.allWarningsAsErrors = true
}
}
}
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/teamcity-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.gradle.kotlin.dsl.*

val teamcitySuffix = findProperty("teamcitySuffix")?.toString()
if (teamcityInteractionEnabled && hasProperty("teamcity") && !propertyIsTrue("build_snapshot_train")) {
// Tell teamcity about version number
val postfix = if (teamcitySuffix == null) "" else " ($teamcitySuffix)"
println("##teamcity[buildNumber '${project.version}${postfix}']")

gradle.taskGraph.beforeTask {
println("##teamcity[progressMessage 'Gradle: ${path}:${name}']")
tasks.configureEach {
doFirst {
println("##teamcity[progressMessage 'Gradle: ${path}:${name}']")
}
}
}
9 changes: 9 additions & 0 deletions buildSrc/src/main/kotlin/utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import java.util.Locale

/*
* Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

fun String.capitalizeCompat() = replaceFirstChar {
if (it.isLowerCase()) it.titlecase(locale = Locale.getDefault()) else it.toString()
}
Loading