2.8 KiB
2.8 KiB
Gradle buildscript utilities for Kotlin/Multiplatform
Getting
As library
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*
buildscript {
repositories {
mavenCentral()
maven("https://maven.landgrafhomyak.ru/")
}
dependencies {
classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.2k2.0.20")
}
}
plugins {
kotlin("multiplatform") version "2.0.20" // version of kotlin must be same as in this library
}
repositories {
mavenCentral()
}
kotlin {
optInContracts()
// ...
defineAllMultiplatformTargets()
sourceSets {
// ...
}
}
As plugin (custom repository)
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.plugin.xomrk
buildscript {
repositories {
mavenCentral()
maven("https://maven.landgrafhomyak.ru/")
}
dependencies {
classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build:v0.2k2.0.20")
}
}
plugins {
// kotlin/multiplatorm and other plugins will be lazily enabled by dsl
}
repositories {
mavenCentral()
}
xomrk {
// lazily enables kotlin if not yet
kotlin {
// same as with original kotlin plugin
}
}
As plugin (gradle portal)
This library officially isn't published, so this way wouldn't work
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*
plugins {
id("ru.landgrafhomyak.kotlin.original-multiplatform-ext") version "v0.2k2.0.20"
}
repositories {
mavenCentral()
}
xomrk {
// lazily enables kotlin if not yet
kotlin {
// same as with original kotlin plugin
}
}
Functionality
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*
// ...
kotlin {
// Configures compilations of all targets
configureAllCompilations { }
// Configures compiler for all targets
configureAllCompilersOptions { }
// Removes warning "expect/actual mechanism is experimental"
noWarnExpectActual()
warningsAsErrors()
// Opt-ins specified annotation to all targets
optIn("org.example.OptIn")
// optIn("kotlin.contracts.ExperimentalContracts")
optInContracts()
// sets kotlin compatibility (both api and language) for all targets
setCompatibilityWithKotlin(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
// defines all possible targets, useful for 'algorithm' libraries that are not depends on platform
defineAllMultiplatformTargets()
}
publishing {
// useful for single-platform (e.g. JVM-only) libraries
forceSetAllMavenArtifactsId(project.name)
// safe replacing for libraries with many targets
replaceAllMavenArtifactsIdPrefixes(project.name, "custom-name")
// replacing of platform id (but better to do it in kotlin {...} block)
replaceAllMavenArtifactsIdSuffixes("js", "frontend")
}