[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.KotlinSingleJavaTargetExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
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.configureDefaultPublishing
|
||||||
import plugins.configureKotlinPomAttributes
|
import plugins.configureKotlinPomAttributes
|
||||||
import java.net.URL
|
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
|
// Common outputs will also produce '${project.name}.kotlin_module' file, so we need to avoid
|
||||||
// files clash
|
// files clash
|
||||||
tasks.named<KotlinCompile>("compile${commonSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
tasks.named<KotlinJvmCompile>("compile${commonSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
||||||
@Suppress("DEPRECATION")
|
compilerOptions.moduleName.set("${this@createGradleCommonSourceSet.name}_${commonSourceSet.name}")
|
||||||
kotlinOptions {
|
|
||||||
moduleName = "${this@createGradleCommonSourceSet.name}_${commonSourceSet.name}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerValidatePluginTasks(commonSourceSet)
|
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
|
// 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") {
|
tasks.named<KotlinJvmCompile>("compile${variantSourceSet.name.replaceFirstChar { it.uppercase() }}Kotlin") {
|
||||||
@Suppress("DEPRECATION")
|
compilerOptions.moduleName.set(this@createGradlePluginVariant.name)
|
||||||
kotlinOptions {
|
|
||||||
moduleName = this@createGradlePluginVariant.name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -546,7 +540,7 @@ private fun Project.commonVariantAttributes(): Action<Configuration> = Action<Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Project.configureKotlinCompileTasksGradleCompatibility() {
|
fun Project.configureKotlinCompileTasksGradleCompatibility() {
|
||||||
tasks.withType<KotlinCompile>().configureEach {
|
tasks.withType<KotlinJvmCompile>().configureEach {
|
||||||
compilerOptions {
|
compilerOptions {
|
||||||
// check https://docs.gradle.org/current/userguide/compatibility.html#kotlin for Kotlin-Gradle versions matrix
|
// 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
|
@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:
|
// which leads to the content of that JAR being excluded as well:
|
||||||
exclude {
|
exclude {
|
||||||
// Docstring says `file` never returns null, but it does
|
// 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
|
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.jvm.toolchain.*
|
||||||
import org.gradle.kotlin.dsl.getByType
|
import org.gradle.kotlin.dsl.getByType
|
||||||
import org.gradle.kotlin.dsl.withType
|
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.dsl.KotlinTopLevelExtension
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||||
|
|
||||||
enum class JdkMajorVersion(
|
enum class JdkMajorVersion(
|
||||||
val majorVersion: Int,
|
val majorVersion: Int,
|
||||||
@@ -114,7 +115,7 @@ fun Project.chooseJdk_1_8ForJpsBuild(jdkVersion: JdkMajorVersion): JdkMajorVersi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinCompile.configureTaskToolchain(
|
fun KotlinJvmCompile.configureTaskToolchain(
|
||||||
jdkVersion: JdkMajorVersion
|
jdkVersion: JdkMajorVersion
|
||||||
) {
|
) {
|
||||||
if (project.shouldOverrideObsoleteJdk(jdkVersion)) {
|
if (project.shouldOverrideObsoleteJdk(jdkVersion)) {
|
||||||
@@ -123,10 +124,7 @@ fun KotlinCompile.configureTaskToolchain(
|
|||||||
jdkVersion.overrideVersion ?: error("Substitution version should be defined for override mode")
|
jdkVersion.overrideVersion ?: error("Substitution version should be defined for override mode")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@Suppress("DEPRECATION")
|
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(jdkVersion.targetName))
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = jdkVersion.targetName
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
kotlinJavaToolchain.toolchain.use(
|
kotlinJavaToolchain.toolchain.use(
|
||||||
project.getToolchainLauncherFor(jdkVersion)
|
project.getToolchainLauncherFor(jdkVersion)
|
||||||
@@ -161,11 +159,10 @@ fun Project.updateJvmTarget(
|
|||||||
}
|
}
|
||||||
// Java 9 tasks are exceptions that are configured in configureJava9Compilation
|
// Java 9 tasks are exceptions that are configured in configureJava9Compilation
|
||||||
tasks
|
tasks
|
||||||
.withType<KotlinCompile>()
|
.withType<KotlinJvmCompile>()
|
||||||
.matching { it.name != "compileJava9Kotlin" }
|
.matching { it.name != "compileJava9Kotlin" }
|
||||||
.configureEach {
|
.configureEach {
|
||||||
@Suppress("DEPRECATION")
|
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(jvmTarget))
|
||||||
kotlinOptions.jvmTarget = jvmTarget
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks
|
tasks
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import org.gradle.api.plugins.BasePluginExtension
|
|||||||
import org.gradle.api.tasks.compile.JavaCompile
|
import org.gradle.api.tasks.compile.JavaCompile
|
||||||
import org.gradle.kotlin.dsl.*
|
import org.gradle.kotlin.dsl.*
|
||||||
import org.gradle.process.CommandLineArgumentProvider
|
import org.gradle.process.CommandLineArgumentProvider
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@@ -31,10 +31,11 @@ fun Project.configureJava9Compilation(
|
|||||||
|
|
||||||
val kotlinCompileTaskNames = setOf("compile${sourceSetNameC}Kotlin", "compile${sourceSetNameC}KotlinJvm")
|
val kotlinCompileTaskNames = setOf("compile${sourceSetNameC}Kotlin", "compile${sourceSetNameC}KotlinJvm")
|
||||||
|
|
||||||
tasks.withType(KotlinCompile::class.java).matching { it.name in kotlinCompileTaskNames }.configureEach {
|
tasks.withType<KotlinJvmCompile>().configureEach {
|
||||||
configureTaskToolchain(JdkMajorVersion.JDK_9_0)
|
if (name in kotlinCompileTaskNames) {
|
||||||
@Suppress("DEPRECATION")
|
configureTaskToolchain(JdkMajorVersion.JDK_9_0)
|
||||||
kotlinOptions.jvmTarget = JdkMajorVersion.JDK_9_0.targetName
|
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(JdkMajorVersion.JDK_9_0.targetName))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named("compile${sourceSetNameC}Java", JavaCompile::class.java) {
|
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.dsl.KotlinVersion
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
|
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
|
// Contains common configuration that should be applied to all projects
|
||||||
|
|
||||||
@@ -136,24 +139,24 @@ fun Project.configureKotlinCompilationOptions() {
|
|||||||
":kotlin-dom-api-compat",
|
":kotlin-dom-api-compat",
|
||||||
) - listOf(":kotlin-stdlib", ":kotlin-stdlib-common")
|
) - listOf(":kotlin-stdlib", ":kotlin-stdlib-common")
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
|
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||||
kotlinOptions {
|
compilerOptions {
|
||||||
|
|
||||||
freeCompilerArgs += commonCompilerArgs
|
freeCompilerArgs.addAll(commonCompilerArgs)
|
||||||
val forced19 = project.path in projectsWithForced19LanguageVersion
|
val forced19 = project.path in projectsWithForced19LanguageVersion
|
||||||
if (forced19) {
|
if (forced19) {
|
||||||
languageVersion = "1.9"
|
languageVersion.set(KotlinVersion.KOTLIN_1_9)
|
||||||
apiVersion = "1.9"
|
apiVersion.set(KotlinVersion.KOTLIN_1_9)
|
||||||
} else {
|
} else {
|
||||||
languageVersion = kotlinLanguageVersion
|
languageVersion.set(KotlinVersion.fromVersion(kotlinLanguageVersion))
|
||||||
apiVersion = kotlinLanguageVersion
|
apiVersion.set(KotlinVersion.fromVersion(kotlinLanguageVersion))
|
||||||
freeCompilerArgs += "-Xskip-prerelease-check"
|
freeCompilerArgs.add("-Xskip-prerelease-check")
|
||||||
}
|
}
|
||||||
if (project.path in projectsUsedInIntelliJKotlinPlugin) {
|
if (project.path in projectsUsedInIntelliJKotlinPlugin) {
|
||||||
apiVersion = kotlinApiVersionForProjectsUsedInIntelliJKotlinPlugin
|
apiVersion.set(KotlinVersion.fromVersion(kotlinApiVersionForProjectsUsedInIntelliJKotlinPlugin))
|
||||||
}
|
}
|
||||||
if (KotlinVersion.DEFAULT >= KotlinVersion.KOTLIN_2_0 && forced19) {
|
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") {
|
if (project.path != ":native:kotlin-test-native-xctest") {
|
||||||
doFirst {
|
doFirst {
|
||||||
if (!useAbsolutePathsInKlib) {
|
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 projectsWithEnabledContextReceivers: List<String> by rootProject.extra
|
||||||
val projectsWithOptInToUnsafeCastFunctionsFromAddToStdLib: List<String> by rootProject.extra
|
val projectsWithOptInToUnsafeCastFunctionsFromAddToStdLib: List<String> by rootProject.extra
|
||||||
|
|
||||||
@Suppress("SuspiciousCollectionReassignment", "DEPRECATION")
|
tasks.withType<KotlinJvmCompile>().configureEach {
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile>().configureEach {
|
compilerOptions {
|
||||||
kotlinOptions {
|
freeCompilerArgs.addAll(jvmCompilerArgs)
|
||||||
freeCompilerArgs += jvmCompilerArgs
|
|
||||||
if (renderDiagnosticNames) {
|
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) {
|
if (project.path in projectsWithEnabledContextReceivers) {
|
||||||
freeCompilerArgs += "-Xcontext-receivers"
|
freeCompilerArgs.add("-Xcontext-receivers")
|
||||||
}
|
}
|
||||||
if (project.path in projectsWithOptInToUnsafeCastFunctionsFromAddToStdLib) {
|
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") {
|
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
|
// This change will most likely not be needed after the bootstrap, as soon as kotlin-util-klib is compiled with
|
||||||
// `-Xjvm-default=all`.
|
// `-Xjvm-default=all`.
|
||||||
freeCompilerArgs += "-Xjvm-default=all-compatibility"
|
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
|
||||||
} else if (!skipJvmDefaultAllForModule(project.path)) {
|
} 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.*
|
||||||
import org.gradle.kotlin.dsl.support.serviceOf
|
import org.gradle.kotlin.dsl.support.serviceOf
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.Character.isLowerCase
|
import java.lang.Character.isLowerCase
|
||||||
import java.lang.Character.isUpperCase
|
import java.lang.Character.isUpperCase
|
||||||
@@ -411,10 +412,8 @@ fun Project.confugureFirPluginAnnotationsDependency(testTask: TaskProvider<Test>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.optInTo(annotationFqName: String) {
|
private fun Project.optInTo(annotationFqName: String) {
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
|
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||||
kotlinOptions {
|
compilerOptions.optIn.add(annotationFqName)
|
||||||
freeCompilerArgs += "-opt-in=$annotationFqName"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user