[Gradle] Add api marker to Kotlin compilation tasks DSL

Kotlin's compilation tasks DSL should also be separated from other DSL
parts.

^KT-57292 In Progress
This commit is contained in:
Yahor Berdnikau
2023-12-20 23:39:33 +01:00
committed by Space Team
parent 2af60a5e27
commit ea8f7af1f2
4 changed files with 63 additions and 43 deletions
+58 -43
View File
@@ -1,5 +1,7 @@
@file:Suppress("UNUSED_VARIABLE", "NAME_SHADOWING") @file:Suppress("UNUSED_VARIABLE", "NAME_SHADOWING")
import org.gradle.jvm.tasks.Jar import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
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.plugin.mpp.GenerateProjectStructureMetadata import org.jetbrains.kotlin.gradle.plugin.mpp.GenerateProjectStructureMetadata
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
@@ -71,18 +73,20 @@ kotlin {
compilations { compilations {
all { all {
compileTaskProvider.configure { compileTaskProvider.configure {
kotlinOptions { compilerOptions {
freeCompilerArgs = listOfNotNull( freeCompilerArgs.set(
"-Xallow-kotlin-package", listOfNotNull(
"-module-name", "kotlin-stdlib-common", "-Xallow-kotlin-package",
"-Xexpect-actual-classes", "-module-name", "kotlin-stdlib-common",
"-Xexplicit-api=strict", "-Xexpect-actual-classes",
diagnosticNamesArg, "-Xexplicit-api=strict",
diagnosticNamesArg,
)
) )
// workaround for compiling legacy MPP metadata, remove when this compilation is not needed anymore
// restate the list of opt-ins
compilerOptions.optIn.addAll(commonOptIns)
} }
// workaround for compiling legacy MPP metadata, remove when this compilation is not needed anymore
// restate the list of opt-ins
compilerOptions.optIn.addAll(commonOptIns)
} }
} }
} }
@@ -92,8 +96,8 @@ kotlin {
compilations { compilations {
val compileOnlyDeclarations by creating { val compileOnlyDeclarations by creating {
compileTaskProvider.configure { compileTaskProvider.configure {
kotlinOptions { compilerOptions {
freeCompilerArgs = listOfNotNull("-Xallow-kotlin-package", diagnosticNamesArg) freeCompilerArgs.set(listOfNotNull("-Xallow-kotlin-package", diagnosticNamesArg))
} }
} }
} }
@@ -102,18 +106,20 @@ kotlin {
compileTaskProvider.configure { compileTaskProvider.configure {
this as UsesKotlinJavaToolchain this as UsesKotlinJavaToolchain
kotlinJavaToolchain.toolchain.use(getToolchainLauncherFor(JdkMajorVersion.JDK_1_6)) kotlinJavaToolchain.toolchain.use(getToolchainLauncherFor(JdkMajorVersion.JDK_1_6))
kotlinOptions { compilerOptions {
moduleName = "kotlin-stdlib" moduleName = "kotlin-stdlib"
jvmTarget = "1.8" jvmTarget = JvmTarget.JVM_1_8
// providing exhaustive list of args here // providing exhaustive list of args here
freeCompilerArgs = listOfNotNull( freeCompilerArgs.set(
"-Xallow-kotlin-package", listOfNotNull(
"-Xexpect-actual-classes", "-Xallow-kotlin-package",
"-Xmultifile-parts-inherit", "-Xexpect-actual-classes",
"-Xuse-14-inline-classes-mangling-scheme", "-Xmultifile-parts-inherit",
"-Xbuiltins-from-sources", "-Xuse-14-inline-classes-mangling-scheme",
"-Xno-new-java-annotation-targets", "-Xbuiltins-from-sources",
diagnosticNamesArg, "-Xno-new-java-annotation-targets",
diagnosticNamesArg,
)
) )
} }
} }
@@ -128,15 +134,17 @@ kotlin {
compileTaskProvider.configure { compileTaskProvider.configure {
this as UsesKotlinJavaToolchain this as UsesKotlinJavaToolchain
kotlinJavaToolchain.toolchain.use(getToolchainLauncherFor(JdkMajorVersion.JDK_1_7)) kotlinJavaToolchain.toolchain.use(getToolchainLauncherFor(JdkMajorVersion.JDK_1_7))
kotlinOptions { compilerOptions {
moduleName = "kotlin-stdlib-jdk7" moduleName = "kotlin-stdlib-jdk7"
jvmTarget = "1.8" jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs = listOfNotNull( freeCompilerArgs.set(
"-Xallow-kotlin-package", listOfNotNull(
"-Xmultifile-parts-inherit", "-Xallow-kotlin-package",
"-Xno-new-java-annotation-targets", "-Xmultifile-parts-inherit",
"-Xexplicit-api=strict", "-Xno-new-java-annotation-targets",
diagnosticNamesArg, "-Xexplicit-api=strict",
diagnosticNamesArg,
)
) )
} }
} }
@@ -145,14 +153,16 @@ kotlin {
associateWith(main) associateWith(main)
associateWith(mainJdk7) associateWith(mainJdk7)
compileTaskProvider.configure { compileTaskProvider.configure {
kotlinOptions { compilerOptions {
moduleName = "kotlin-stdlib-jdk8" moduleName = "kotlin-stdlib-jdk8"
freeCompilerArgs = listOfNotNull( freeCompilerArgs.set(
"-Xallow-kotlin-package", listOfNotNull(
"-Xmultifile-parts-inherit", "-Xallow-kotlin-package",
"-Xno-new-java-annotation-targets", "-Xmultifile-parts-inherit",
"-Xexplicit-api=strict", "-Xno-new-java-annotation-targets",
diagnosticNamesArg, "-Xexplicit-api=strict",
diagnosticNamesArg,
)
) )
} }
} }
@@ -169,16 +179,21 @@ kotlin {
associateWith(mainJdk7) associateWith(mainJdk7)
associateWith(mainJdk8) associateWith(mainJdk8)
compileTaskProvider.configure { compileTaskProvider.configure {
kotlinOptions { compilerOptions {
freeCompilerArgs += listOf( freeCompilerArgs.addAll(
"-Xallow-kotlin-package", // TODO: maybe rename test packages listOf(
"-Xexpect-actual-classes", "-Xallow-kotlin-package", // TODO: maybe rename test packages
"-Xexpect-actual-classes",
)
) )
if (kotlinBuildProperties.useFir) { if (kotlinBuildProperties.useFir) {
freeCompilerArgs += "-Xuse-k2" freeCompilerArgs.add("-Xuse-k2")
} }
// This is needed for JavaTypeTest; typeOf for non-reified type parameters doesn't work otherwise, for implementation reasons. // This is needed for JavaTypeTest; typeOf for non-reified type parameters doesn't work otherwise, for implementation reasons.
freeCompilerArgs -= "-Xno-optimized-callable-references" val currentFreeArgs = freeCompilerArgs.get()
freeCompilerArgs
.value(currentFreeArgs.filter { it != "-Xno-optimized-callable-references" })
.finalizeValue()
} }
} }
} }
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
* *
* @see [KotlinCommonOptions] * @see [KotlinCommonOptions]
*/ */
@KotlinGradlePluginDsl
interface KotlinCompile<out T : KotlinCommonOptions> : Task { interface KotlinCompile<out T : KotlinCommonOptions> : Task {
/** /**
@@ -9,6 +9,7 @@ import org.gradle.api.Action
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.tasks.Nested import org.gradle.api.tasks.Nested
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinGradlePluginDsl
/** /**
* Represents a Kotlin task compiling using configurable [compilerOptions]. * Represents a Kotlin task compiling using configurable [compilerOptions].
@@ -17,6 +18,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
* *
* @see [KotlinCommonCompilerOptions] * @see [KotlinCommonCompilerOptions]
*/ */
@KotlinGradlePluginDsl
interface KotlinCompilationTask<out CO : KotlinCommonCompilerOptions> : Task { interface KotlinCompilationTask<out CO : KotlinCommonCompilerOptions> : Task {
/** /**
@@ -9,6 +9,7 @@ import org.gradle.api.Action
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.tasks.Nested import org.gradle.api.tasks.Nested
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinGradlePluginDsl
/** /**
* Represents a Kotlin task performing further processing of compiled code via additional Kotlin tools using configurable [toolOptions]. * Represents a Kotlin task performing further processing of compiled code via additional Kotlin tools using configurable [toolOptions].
@@ -18,6 +19,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions
* *
* @see [KotlinCommonCompilerToolOptions] * @see [KotlinCommonCompilerToolOptions]
*/ */
@KotlinGradlePluginDsl
interface KotlinToolTask<out TO : KotlinCommonCompilerToolOptions> : Task { interface KotlinToolTask<out TO : KotlinCommonCompilerToolOptions> : Task {
/** /**