Shortcuts for configuring compiler
This commit is contained in:
parent
1d473e94b9
commit
464be35d6b
@ -1,4 +1,5 @@
|
|||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "2.0.20"
|
kotlin("multiplatform") version "2.0.20"
|
||||||
@ -23,12 +24,25 @@ repositories {
|
|||||||
kotlin {
|
kotlin {
|
||||||
explicitApi()
|
explicitApi()
|
||||||
jvmToolchain(8)
|
jvmToolchain(8)
|
||||||
|
|
||||||
|
targets.configureEach {
|
||||||
|
this.compilations.configureEach {
|
||||||
|
compileTaskProvider.configure {
|
||||||
|
this.compilerOptions {
|
||||||
|
this.languageVersion.set(KotlinVersion.KOTLIN_1_8)
|
||||||
|
this.apiVersion.set(KotlinVersion.KOTLIN_1_8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
jvm()
|
jvm()
|
||||||
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("dev.gradleplugins:gradle-api:7.5.1")
|
compileOnly("dev.gradleplugins:gradle-api:${versions.getProperty("gradle")}")
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${targetKotlinVersion}")
|
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${targetKotlinVersion}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +50,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
// other settings of publication
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
name = "XomrkMaven"
|
name = "XomrkMaven"
|
||||||
@ -44,7 +57,7 @@ publishing {
|
|||||||
|
|
||||||
credentials(HttpHeaderCredentials::class) {
|
credentials(HttpHeaderCredentials::class) {
|
||||||
name = "Authorization"
|
name = "Authorization"
|
||||||
value = "token ${System.getenv("XOMRK_MAVEN_REPO_DEPLOY_TOKEN")}"
|
value = "token ${System.getenv("XOMRK_GITEA_MAVEN_REPO_DEPLOY_TOKEN")}"
|
||||||
}
|
}
|
||||||
|
|
||||||
authentication {
|
authentication {
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
@file:JvmName("Compilations")
|
||||||
|
|
||||||
|
package ru.landgrafhomyak.kotlin.kmp_gradle_build_helper
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.configureAllCompilations(action: KotlinCompilation<KotlinCommonOptions>.() -> Unit) {
|
||||||
|
this.targets.configureEach { t ->
|
||||||
|
t.compilations.configureEach(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.configureAllCompilersOptions(action: KotlinCommonCompilerOptions.() -> Unit) {
|
||||||
|
this.targets.configureEach { t ->
|
||||||
|
t.compilations.configureEach { c ->
|
||||||
|
c.compileTaskProvider.configure { t ->
|
||||||
|
t.compilerOptions(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.noWarnExpectActual(): Unit =
|
||||||
|
this.configureAllCompilersOptions { this@configureAllCompilersOptions.freeCompilerArgs.add("-Xexpect-actual-classes") }
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.warningsAsErrors(): Unit =
|
||||||
|
this.configureAllCompilersOptions { this@configureAllCompilersOptions.allWarningsAsErrors.set(true) }
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.optIn(classQualname: String): Unit =
|
||||||
|
this.configureAllCompilersOptions { this@configureAllCompilersOptions.optIn.add(classQualname) }
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.optInContracts(): Unit =
|
||||||
|
this.optIn("kotlin.contracts.ExperimentalContracts")
|
||||||
|
|
||||||
|
public fun KotlinMultiplatformExtension.setCompatibilityWithKotlin(version: KotlinVersion): Unit =
|
||||||
|
this.configureAllCompilersOptions {
|
||||||
|
this@configureAllCompilersOptions.apiVersion.set(version)
|
||||||
|
this@configureAllCompilersOptions.languageVersion.set(version)
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineAllMultiplatformTargets
|
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineAllMultiplatformTargets
|
||||||
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineXomrkGiteaMavenRepo
|
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineXomrkGiteaMavenRepo
|
||||||
|
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.optInContracts
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
val versions = java.util.Properties()
|
val versions = java.util.Properties()
|
||||||
@ -28,4 +29,5 @@ repositories {
|
|||||||
kotlin {
|
kotlin {
|
||||||
jvmToolchain(8)
|
jvmToolchain(8)
|
||||||
defineAllMultiplatformTargets()
|
defineAllMultiplatformTargets()
|
||||||
|
optInContracts()
|
||||||
}
|
}
|
||||||
|
8
test/src/commonMain/kotlin/contracts_test.kt
Normal file
8
test/src/commonMain/kotlin/contracts_test.kt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import kotlin.contracts.InvocationKind
|
||||||
|
import kotlin.contracts.contract
|
||||||
|
|
||||||
|
fun lambdaReceiver(f: () -> Unit) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(f, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user