[Repo] Don't use kotlinOptions in buildSrc-compat
Exception is configuring klib relative path which should be fixed via separate issue. ^KT-63419 In Progress
This commit is contained in:
committed by
Space Team
parent
eea3c3624c
commit
22e1e79c41
@@ -35,7 +35,7 @@ import org.jetbrains.dokka.gradle.GradleExternalDocumentationLinkBuilder
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
import plugins.configureDefaultPublishing
|
||||
import plugins.configureKotlinPomAttributes
|
||||
import java.net.URL
|
||||
@@ -179,11 +179,8 @@ fun Project.createGradleCommonSourceSet(): SourceSet {
|
||||
|
||||
// Common outputs will also produce '${project.name}.kotlin_module' file, so we need to avoid
|
||||
// files clash
|
||||
tasks.named<KotlinCompile>("compile${commonSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
||||
@Suppress("DEPRECATION")
|
||||
kotlinOptions {
|
||||
moduleName = "${this@createGradleCommonSourceSet.name}_${commonSourceSet.name}"
|
||||
}
|
||||
tasks.named<KotlinJvmCompile>("compile${commonSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
||||
compilerOptions.moduleName.set("${this@createGradleCommonSourceSet.name}_${commonSourceSet.name}")
|
||||
}
|
||||
|
||||
registerValidatePluginTasks(commonSourceSet)
|
||||
@@ -508,11 +505,8 @@ fun Project.createGradlePluginVariant(
|
||||
}
|
||||
|
||||
// KT-52138: Make module name the same for all variants, so KSP could access internal methods/properties
|
||||
tasks.named<KotlinCompile>("compile${variantSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
||||
@Suppress("DEPRECATION")
|
||||
kotlinOptions {
|
||||
moduleName = this@createGradlePluginVariant.name
|
||||
}
|
||||
tasks.named<KotlinJvmCompile>("compile${variantSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
||||
compilerOptions.moduleName.set(this@createGradlePluginVariant.name)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -546,7 +540,7 @@ private fun Project.commonVariantAttributes(): Action<Configuration> = Action<Co
|
||||
}
|
||||
|
||||
fun Project.configureKotlinCompileTasksGradleCompatibility() {
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
tasks.withType<KotlinJvmCompile>().configureEach {
|
||||
compilerOptions {
|
||||
// check https://docs.gradle.org/current/userguide/compatibility.html#kotlin for Kotlin-Gradle versions matrix
|
||||
@Suppress("DEPRECATION") // we can't use language version greater than 1.5 as minimal supported Gradle embeds Kotlin 1.4
|
||||
@@ -591,7 +585,7 @@ fun Project.publishShadowedJar(
|
||||
// which leads to the content of that JAR being excluded as well:
|
||||
exclude {
|
||||
// Docstring says `file` never returns null, but it does
|
||||
@Suppress("UNNECESSARY_SAFE_CALL", "SAFE_CALL_WILL_CHANGE_NULLABILITY")
|
||||
@Suppress("UNNECESSARY_SAFE_CALL")
|
||||
it.file?.name?.startsWith("kotlin-compiler-embeddable") ?: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.jvm.toolchain.*
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
|
||||
enum class JdkMajorVersion(
|
||||
val majorVersion: Int,
|
||||
@@ -114,7 +115,7 @@ fun Project.chooseJdk_1_8ForJpsBuild(jdkVersion: JdkMajorVersion): JdkMajorVersi
|
||||
}
|
||||
}
|
||||
|
||||
fun KotlinCompile.configureTaskToolchain(
|
||||
fun KotlinJvmCompile.configureTaskToolchain(
|
||||
jdkVersion: JdkMajorVersion
|
||||
) {
|
||||
if (project.shouldOverrideObsoleteJdk(jdkVersion)) {
|
||||
@@ -123,10 +124,7 @@ fun KotlinCompile.configureTaskToolchain(
|
||||
jdkVersion.overrideVersion ?: error("Substitution version should be defined for override mode")
|
||||
)
|
||||
)
|
||||
@Suppress("DEPRECATION")
|
||||
kotlinOptions {
|
||||
jvmTarget = jdkVersion.targetName
|
||||
}
|
||||
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(jdkVersion.targetName))
|
||||
} else {
|
||||
kotlinJavaToolchain.toolchain.use(
|
||||
project.getToolchainLauncherFor(jdkVersion)
|
||||
@@ -161,11 +159,10 @@ fun Project.updateJvmTarget(
|
||||
}
|
||||
// Java 9 tasks are exceptions that are configured in configureJava9Compilation
|
||||
tasks
|
||||
.withType<KotlinCompile>()
|
||||
.withType<KotlinJvmCompile>()
|
||||
.matching { it.name != "compileJava9Kotlin" }
|
||||
.configureEach {
|
||||
@Suppress("DEPRECATION")
|
||||
kotlinOptions.jvmTarget = jvmTarget
|
||||
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(jvmTarget))
|
||||
}
|
||||
|
||||
tasks
|
||||
|
||||
@@ -14,8 +14,8 @@ import org.gradle.api.plugins.BasePluginExtension
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.gradle.process.CommandLineArgumentProvider
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
|
||||
@JvmOverloads
|
||||
@@ -31,10 +31,11 @@ fun Project.configureJava9Compilation(
|
||||
|
||||
val kotlinCompileTaskNames = setOf("compile${sourceSetNameC}Kotlin", "compile${sourceSetNameC}KotlinJvm")
|
||||
|
||||
tasks.withType(KotlinCompile::class.java).matching { it.name in kotlinCompileTaskNames }.configureEach {
|
||||
configureTaskToolchain(JdkMajorVersion.JDK_9_0)
|
||||
@Suppress("DEPRECATION")
|
||||
kotlinOptions.jvmTarget = JdkMajorVersion.JDK_9_0.targetName
|
||||
tasks.withType<KotlinJvmCompile>().configureEach {
|
||||
if (name in kotlinCompileTaskNames) {
|
||||
configureTaskToolchain(JdkMajorVersion.JDK_9_0)
|
||||
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(JdkMajorVersion.JDK_9_0.targetName))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("compile${sourceSetNameC}Java", JavaCompile::class.java) {
|
||||
|
||||
+24
-21
@@ -1,5 +1,8 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
|
||||
// Contains common configuration that should be applied to all projects
|
||||
|
||||
@@ -136,24 +139,24 @@ fun Project.configureKotlinCompilationOptions() {
|
||||
":kotlin-dom-api-compat",
|
||||
) - listOf(":kotlin-stdlib", ":kotlin-stdlib-common")
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
|
||||
kotlinOptions {
|
||||
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||
compilerOptions {
|
||||
|
||||
freeCompilerArgs += commonCompilerArgs
|
||||
freeCompilerArgs.addAll(commonCompilerArgs)
|
||||
val forced19 = project.path in projectsWithForced19LanguageVersion
|
||||
if (forced19) {
|
||||
languageVersion = "1.9"
|
||||
apiVersion = "1.9"
|
||||
languageVersion.set(KotlinVersion.KOTLIN_1_9)
|
||||
apiVersion.set(KotlinVersion.KOTLIN_1_9)
|
||||
} else {
|
||||
languageVersion = kotlinLanguageVersion
|
||||
apiVersion = kotlinLanguageVersion
|
||||
freeCompilerArgs += "-Xskip-prerelease-check"
|
||||
languageVersion.set(KotlinVersion.fromVersion(kotlinLanguageVersion))
|
||||
apiVersion.set(KotlinVersion.fromVersion(kotlinLanguageVersion))
|
||||
freeCompilerArgs.add("-Xskip-prerelease-check")
|
||||
}
|
||||
if (project.path in projectsUsedInIntelliJKotlinPlugin) {
|
||||
apiVersion = kotlinApiVersionForProjectsUsedInIntelliJKotlinPlugin
|
||||
apiVersion.set(KotlinVersion.fromVersion(kotlinApiVersionForProjectsUsedInIntelliJKotlinPlugin))
|
||||
}
|
||||
if (KotlinVersion.DEFAULT >= KotlinVersion.KOTLIN_2_0 && forced19) {
|
||||
options.progressiveMode.set(false)
|
||||
progressiveMode.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +171,8 @@ fun Project.configureKotlinCompilationOptions() {
|
||||
if (project.path != ":native:kotlin-test-native-xctest") {
|
||||
doFirst {
|
||||
if (!useAbsolutePathsInKlib) {
|
||||
kotlinOptions.freeCompilerArgs += "-Xklib-relative-path-base=${layout.buildDirectory.get().asFile},${layout.projectDirectory.asFile},$rootDir"
|
||||
(this as KotlinCompile<*>).kotlinOptions.freeCompilerArgs +=
|
||||
"-Xklib-relative-path-base=${layout.buildDirectory.get().asFile},${layout.projectDirectory.asFile},$rootDir"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,19 +186,18 @@ fun Project.configureKotlinCompilationOptions() {
|
||||
val projectsWithEnabledContextReceivers: List<String> by rootProject.extra
|
||||
val projectsWithOptInToUnsafeCastFunctionsFromAddToStdLib: List<String> by rootProject.extra
|
||||
|
||||
@Suppress("SuspiciousCollectionReassignment", "DEPRECATION")
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += jvmCompilerArgs
|
||||
tasks.withType<KotlinJvmCompile>().configureEach {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll(jvmCompilerArgs)
|
||||
if (renderDiagnosticNames) {
|
||||
freeCompilerArgs += "-Xrender-internal-diagnostic-names"
|
||||
freeCompilerArgs.add("-Xrender-internal-diagnostic-names")
|
||||
}
|
||||
allWarningsAsErrors = !kotlinBuildProperties.disableWerror
|
||||
allWarningsAsErrors.set(!kotlinBuildProperties.disableWerror)
|
||||
if (project.path in projectsWithEnabledContextReceivers) {
|
||||
freeCompilerArgs += "-Xcontext-receivers"
|
||||
freeCompilerArgs.add("-Xcontext-receivers")
|
||||
}
|
||||
if (project.path in projectsWithOptInToUnsafeCastFunctionsFromAddToStdLib) {
|
||||
freeCompilerArgs += "-opt-in=org.jetbrains.kotlin.utils.addToStdlib.UnsafeCastFunction"
|
||||
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.utils.addToStdlib.UnsafeCastFunction")
|
||||
}
|
||||
|
||||
if (project.path == ":kotlin-util-klib") {
|
||||
@@ -213,9 +216,9 @@ fun Project.configureKotlinCompilationOptions() {
|
||||
//
|
||||
// This change will most likely not be needed after the bootstrap, as soon as kotlin-util-klib is compiled with
|
||||
// `-Xjvm-default=all`.
|
||||
freeCompilerArgs += "-Xjvm-default=all-compatibility"
|
||||
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
|
||||
} else if (!skipJvmDefaultAllForModule(project.path)) {
|
||||
freeCompilerArgs += "-Xjvm-default=all"
|
||||
freeCompilerArgs.add("-Xjvm-default=all")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.gradle.kotlin.dsl.support.serviceOf
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
|
||||
import java.io.File
|
||||
import java.lang.Character.isLowerCase
|
||||
import java.lang.Character.isUpperCase
|
||||
@@ -411,10 +412,8 @@ fun Project.confugureFirPluginAnnotationsDependency(testTask: TaskProvider<Test>
|
||||
}
|
||||
|
||||
private fun Project.optInTo(annotationFqName: String) {
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += "-opt-in=$annotationFqName"
|
||||
}
|
||||
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||
compilerOptions.optIn.add(annotationFqName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user