CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-kotlin--kotlin-gradle-plugin

Official Gradle plugin for the Kotlin programming language that provides comprehensive build support for Kotlin projects including compilation, multiplatform development, Android integration, and native development capabilities

Pending
Overview
Eval results
Files

dsl-extensions.mddocs/

DSL Extensions

This document covers the Kotlin Gradle Plugin's Domain Specific Language (DSL) extensions for configuring Kotlin projects.

Core Project Extension

KotlinProjectExtension

The base extension available in all Kotlin projects.

interface KotlinProjectExtension {
    val sourceSets: NamedDomainObjectContainer<KotlinSourceSet>
    val compilerOptions: KotlinJvmCompilerOptions // or platform-specific options
    
    fun sourceSets(configure: NamedDomainObjectContainer<KotlinSourceSet>.() -> Unit)
}

Usage Example:

kotlin {
    compilerOptions {
        jvmTarget.set(JvmTarget.JVM_11)
        freeCompilerArgs.add("-Xjsr305=strict")
    }
    
    sourceSets {
        main {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib")
            }
        }
        test {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-test")
            }
        }
    }
}

Multiplatform Extension

KotlinMultiplatformExtension

The main DSL extension for multiplatform projects.

interface KotlinMultiplatformExtension : KotlinProjectExtension {
    // Target creation functions
    fun jvm(name: String = "jvm", configure: KotlinJvmTarget.() -> Unit = {}): KotlinJvmTarget
    fun js(name: String = "js", compiler: KotlinJsCompilerType = KotlinJsCompilerType.IR, configure: KotlinJsTarget.() -> Unit = {}): KotlinJsTarget
    fun android(configure: KotlinAndroidTarget.() -> Unit = {}): KotlinAndroidTarget
    
    // Native targets
    fun iosX64(name: String = "iosX64", configure: KotlinNativeTarget.() -> Unit = {}): KotlinNativeTarget
    fun iosArm64(name: String = "iosArm64", configure: KotlinNativeTarget.() -> Unit = {}): KotlinNativeTarget
    fun macosX64(name: String = "macosX64", configure: KotlinNativeTarget.() -> Unit = {}): KotlinNativeTarget
    fun linuxX64(name: String = "linuxX64", configure: KotlinNativeTarget.() -> Unit = {}): KotlinNativeTarget
    fun mingwX64(name: String = "mingwX64", configure: KotlinNativeTarget.() -> Unit = {}): KotlinNativeTarget
    
    // WASM targets
    fun wasmJs(name: String = "wasmJs", configure: KotlinWasmJsTarget.() -> Unit = {}): KotlinWasmJsTarget
    fun wasmWasi(name: String = "wasmWasi", configure: KotlinWasmWasiTarget.() -> Unit = {}): KotlinWasmWasiTarget
    
    // Source set hierarchy
    val sourceSets: KotlinSourceSetContainer
}

Usage Example:

kotlin {
    // Configure targets
    jvm {
        jvmTarget = JvmTarget.JVM_11
    }
    
    js(IR) {
        browser {
            webpackTask {
                outputFileName = "app.js"
            }
        }
        nodejs()
    }
    
    iosX64()
    iosArm64()
    
    // Configure source sets
    sourceSets {
        commonMain {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
            }
        }
        jvmMain {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
            }
        }
        jsMain {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
            }
        }
        nativeMain {
            dependsOn(commonMain.get())
        }
        iosMain {
            dependsOn(nativeMain.get())
        }
    }
}

Compiler Options

KotlinJvmCompilerOptions

JVM-specific compiler options.

interface KotlinJvmCompilerOptions : KotlinCommonCompilerOptions {
    val jvmTarget: Property<JvmTarget>
    val javaParameters: Property<Boolean>
    val useIR: Property<Boolean>
}

KotlinJsCompilerOptions

JavaScript-specific compiler options.

interface KotlinJsCompilerOptions : KotlinCommonCompilerOptions {
    val sourceMap: Property<Boolean>
    val sourceMapEmbedSources: Property<SourceMapEmbedSources>
    val target: Property<String>
    val moduleKind: Property<KotlinJsModuleKind>
}

KotlinNativeCompilerOptions

Native-specific compiler options.

interface KotlinNativeCompilerOptions : KotlinCommonCompilerOptions {
    val debuggable: Property<Boolean>
    val optimized: Property<Boolean>
}

KotlinCommonCompilerOptions

Common compiler options shared across all platforms.

interface KotlinCommonCompilerOptions {
    val languageVersion: Property<KotlinVersion>
    val apiVersion: Property<KotlinVersion>
    val suppressWarnings: Property<Boolean>
    val verbose: Property<Boolean>
    val freeCompilerArgs: ListProperty<String>
    val allWarningsAsErrors: Property<Boolean>
    val progressiveMode: Property<Boolean>
}

Usage Example:

kotlin {
    compilerOptions {
        languageVersion.set(KotlinVersion.KOTLIN_2_0)
        apiVersion.set(KotlinVersion.KOTLIN_2_0)
        freeCompilerArgs.addAll(
            "-Xjsr305=strict",
            "-Xcontext-receivers"
        )
        allWarningsAsErrors.set(true)
    }
}

Source Set Configuration

KotlinSourceSet

Configuration for individual source sets.

interface KotlinSourceSet {
    val name: String
    val kotlin: SourceDirectorySet
    val resources: SourceDirectorySet
    val dependencies: KotlinDependencyHandler
    
    fun dependsOn(other: KotlinSourceSet)
    fun dependencies(configure: KotlinDependencyHandler.() -> Unit)
}

KotlinSourceSetContainer

Container for managing source sets.

interface KotlinSourceSetContainer : NamedDomainObjectContainer<KotlinSourceSet> {
    val commonMain: NamedDomainObjectProvider<KotlinSourceSet>
    val commonTest: NamedDomainObjectProvider<KotlinSourceSet>
    
    // Platform-specific source sets created based on targets
    fun getByName(name: String): KotlinSourceSet
    fun create(name: String, configure: KotlinSourceSet.() -> Unit = {}): KotlinSourceSet
}

Usage Example:

kotlin {
    sourceSets {
        // Common source sets
        commonMain {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
            }
        }
        
        commonTest {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-test")
            }
        }
        
        // Platform-specific source sets
        jvmMain {
            dependencies {
                implementation("ch.qos.logback:logback-classic:1.4.11")
            }
        }
        
        jsMain {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.9.1")
            }
        }
        
        // Custom source set hierarchy
        val nativeMain by creating {
            dependsOn(commonMain.get())
        }
        
        val iosMain by creating {
            dependsOn(nativeMain)
        }
    }
}

Extension Accessors

Helper functions to access platform-specific extensions.

// Extension accessors
fun Project.kotlinExtension(): KotlinProjectExtension
fun Project.multiplatformExtension(): KotlinMultiplatformExtension
fun Project.kotlinJvmExtension(): KotlinJvmProjectExtension
fun Project.kotlinAndroidExtension(): KotlinAndroidProjectExtension

Container Interfaces

KotlinTargetsContainer

Interface for managing multiple targets.

interface KotlinTargetsContainer {
    fun <T : KotlinTarget> findByName(name: String): T?
    fun <T : KotlinTarget> getByName(name: String): T
    val targets: DomainObjectSet<KotlinTarget>
}

KotlinTargetContainerWithPresetFunctions

Extended container with preset functions for common target types.

interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainer {
    fun jvm(): KotlinJvmTarget
    fun android(): KotlinAndroidTarget
    fun js(): KotlinJsTarget
    fun linuxX64(): KotlinNativeTarget
    fun macosX64(): KotlinNativeTarget
    fun iosX64(): KotlinNativeTarget
}

Install with Tessl CLI

npx tessl i tessl/maven-org-jetbrains-kotlin--kotlin-gradle-plugin

docs

compilation-tasks.md

dependency-management.md

dsl-extensions.md

index.md

javascript-webassembly.md

multiplatform-targets.md

plugin-configuration.md

tile.json