KotlinCompilation

Kotlin compilation

Represents the configuration of a Kotlin Compiler invocation. The KotlinCompilation API is designed to ensure the correct and consistent propagation of any compilation changes to all underlying tasks and configurations. Use the KotlinCompilation API instead of getting tasks, configurations, and other related domain objects directly through the Gradle API. For Native targets, KotlinCompilation also provides an API to configure cinterop.

A KotlinTarget contains multiple KotlinCompilations. By default, a KotlinTarget contains two KotlinCompilations with the names "main" and "test".

Here's an example of how to use a KotlinCompilation to configure compilation tasks for the JVM target:

// build.gradle.kts
kotlin {
jvm {
compilations.all {
compileTaskProvider {
// Configure the compile task here
}
}
}
}

Main compilation

The KotlinCompilation with the name "main" represents a Kotlin compiler invocation for the main sources of the KotlinTarget. The results of the main compilation are publishable and exposed via the KotlinTarget.apiElementsConfigurationName consumable configuration.

Here's an example of how to use consume the outputs of the main JVM Compilation for custom processing:

// build.gradle.kts
val jvmMainClasses = kotlin.jvm().compilations.getByName("main").output.classesDirs
tasks.register<Jar>("customJar") {
from(jvmMainClasses)
}

Test compilation

The KotlinCompilation with the name "test" represents a Kotlin Compiler invocation for the test source sets. The test compilation is implicitly associated with the main compilation. See KotlinCompilation.associatedCompilations for more information. This means that the test compilation sees all dependencies, internal and public declarations of the main compilation.

Custom compilation

It is possible to create additional custom compilations for a KotlinTarget:

kotlin {
jvm {
compilations.create("customCompilation")
}
}

Use a separate Gradle project instead of creating a custom compilation for an easier and safer setup.

Metadata target compilation

The Kotlin metadata target is a special KotlinTarget that manages compiler invocations that compile the code of shared source sets. There are no "main" or "test" Kotlin Compilations for the Metadata Target. Instead, there is a dedicated compilation for each shared source set.

Types

Link copied to clipboard
object Companion

Constants for the KotlinCompilation.

Properties

Link copied to clipboard

A full transitive closure of associatedCompilations.

Link copied to clipboard

All KotlinSourceSets used by this compilation.

Link copied to clipboard

The name of the Gradle Configuration that contains api dependencies.

Link copied to clipboard

A list of all compilations that were previously associated with this compilation using associateWith.

Link copied to clipboard
abstract val compilationName: String

The name of the compilation.

Link copied to clipboard

The Gradle task name that is used as a meta task to trigger all the required compilation tasks for this KotlinCompilation.

Link copied to clipboard

The name of the Gradle configuration containing all the resolved dependencies required for compilation.

Link copied to clipboard

A collection of file system locations for the artifacts of compilation dependencies.

Link copied to clipboard

The Kotlin Gradle plugin task name that is used to run the compilation process for this Kotlin compilation.

Link copied to clipboard

The name of the Gradle Configuration containing compileOnly dependencies.

Link copied to clipboard

Provides access to the compilation task for this compilation.

Link copied to clipboard

The KotlinSourceSet by default associated with this compilation.

Link copied to clipboard

A unique name for this compilation in the project.

Link copied to clipboard
abstract override val extras: MutableExtras
Link copied to clipboard

The name of the Gradle Configuration that contains implementation dependencies.

Link copied to clipboard

All KotlinSourceSets used by this compilation.

Link copied to clipboard

Represents the output of a Kotlin compilation.

Link copied to clipboard

Represents the KotlinPlatformType to which this compilation belongs.

Link copied to clipboard
abstract val project: Project

The Gradle Project associated with the entity.

Link copied to clipboard

The name of the Gradle configuration containing all the resolved dependencies required to run compilation output.

Link copied to clipboard

A collection of file system locations for the artifacts of runtime dependencies.

Link copied to clipboard

The name of the Gradle Configuration containing runtimeOnly dependencies.

Link copied to clipboard
abstract val target: KotlinTarget

Represents a KotlinTarget which this compilation belongs to.

Functions

Link copied to clipboard
abstract fun associateWith(other: KotlinCompilation<*>)

Associates the current KotlinCompilation with another KotlinCompilation.

Link copied to clipboard
open fun attributes(configure: AttributeContainer.() -> Unit)
open fun attributes(configure: Action<AttributeContainer>)

Configures the compilation AttributeContainer with the provided configuration.

Link copied to clipboard
abstract fun defaultSourceSet(configure: KotlinSourceSet.() -> Unit)

Configures the provided defaultSourceSet.

Link copied to clipboard
abstract fun dependencies(configure: KotlinDependencyHandler.() -> Unit)
abstract fun dependencies(configure: Action<KotlinDependencyHandler>)

Configures all dependencies for this entity.

Link copied to clipboard
Link copied to clipboard
open override fun getName(): String

The object's name.

Link copied to clipboard
abstract fun source(sourceSet: KotlinSourceSet)

Will add a KotlinSourceSet directly into this compilation. This method is deprecated and is soon to be removed.