Skip to content

Commit

Permalink
chore: fix kotlin gradle DSL deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshg committed Mar 20, 2024
1 parent 5516177 commit 34bd1db
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.gradle.plugin.use.PluginDependency
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

/** Java version properties. */
val Project.javaVersion
Expand Down Expand Up @@ -165,11 +164,6 @@ fun LanguageSettingsBuilder.configureKotlinLang() {
optIn("kotlin.js.ExperimentalJsExport")
}

context(Project)
fun KotlinJvmTest.configureKotlinTest() {
configureJavaTest()
}

context(Project)
fun Test.configureJavaTest() {
useJUnitPlatform()
Expand All @@ -192,8 +186,8 @@ fun Test.configureJavaTest() {
}

context(Project)
fun KotlinJsOptions.configureKotlinJs() {
// useEsClasses = true
fun KotlinJsCompilerOptions.configureKotlinJs() {
useEsClasses = true
// sourceMap = true
// sourceMapEmbedSources = "always"
// freeCompilerArgs += listOf("-Xir-per-module")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.dsl.jvm.JvmTargetValidationMode
import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
import org.jetbrains.kotlin.gradle.targets.js.yarn.*
import tasks.BuildConfig

Expand All @@ -27,33 +26,25 @@ val kotlinMultiplatform = extensions.getByType<KotlinMultiplatformExtension>()

kotlinMultiplatform.apply {
applyDefaultHierarchyTemplate()

jvmToolchain { configureJvmToolchain() }

targets.all {
// Configure all compilations of all targets
compilations.all { compilerOptions.configure { configureKotlinCommon() } }
compilations.all {
compileTaskProvider.configure { compilerOptions { configureKotlinCommon() } }
}
}

jvm {
withJava()
compilations.all {
compileJavaTaskProvider?.configure { configureJavac() }
compilerOptions.configure { configureKotlinJvm() }
compileTaskProvider.configure { compilerOptions { configureKotlinJvm() } }
}

// ./gradlew jvmRun
mainRun { mainClass = libs.versions.app.mainclass.get() }
// val test by testRuns.existing
testRuns.configureEach { executionTask.configure { configureKotlinTest() } }
attributes.attribute(mppTargetAttr, "jvm")
}

jvm("desktop") {
compilations.all {
compileJavaTaskProvider?.configure { configureJavac() }
compilerOptions.configure { configureKotlinJvm() }
}
testRuns.configureEach { executionTask.configure { configureKotlinTest() } }
attributes.attribute(mppTargetAttr, "desktop")
testRuns.configureEach { executionTask.configure { configureJavaTest() } }
}

js(IR) {
Expand All @@ -78,30 +69,6 @@ kotlinMultiplatform.apply {
}
}

// Disable wasm by default as some of the common dependencies are not compatible with wasm.
if (project.hasProperty("experimental")) {

wasmJs {
binaries.executable()
browser {
commonWebpackConfig(
Action {
devServer =
(devServer ?: KotlinWebpackConfig.DevServer()).copy(
open = mapOf("app" to mapOf("name" to "google chrome")))
})
}
}

// Use custom allocator for native targets
macosX64("native") {
binaries.executable()
compilations.configureEach {
compilerOptions.configure { freeCompilerArgs.add("-Xallocator=custom") }
}
}
}

@Suppress("UNUSED_VARIABLE")
this.sourceSets {
all {
Expand Down Expand Up @@ -186,7 +153,6 @@ tasks {
// Register buildConfig task only for common module
val buildConfig by registering(BuildConfig::class) { classFqName = "BuildConfig" }
kotlinMultiplatform.sourceSets.named("commonMain") { kotlin.srcDirs(buildConfig) }
maybeRegister<Task>("prepareKotlinIdeaImport") { dependsOn(buildConfig) }
}

// configure jvm target for ksp
Expand All @@ -195,7 +161,7 @@ tasks {
jvmTargetValidationMode = JvmTargetValidationMode.WARNING
}

withType<KotlinJsCompile>().configureEach { kotlinOptions { configureKotlinJs() } }
withType<KotlinJsCompile>().configureEach { compilerOptions { configureKotlinJs() } }

withType<KotlinNpmInstallTask>().configureEach { configureKotlinNpm() }

Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
java = "23"
kotlin = "2.0.0-Beta4"
kotlin = "2.0.0-Beta5"
kotlin-ksp = "2.0.0-Beta4-1.0.19"
kotlin-jvmtarget = "21"
kotlin-dsl-jvmtarget = "21"
kotlin-api-version = "1.9"
kotlin-lang-version = "2.0"
gradle = "8.7-rc-3"
gradle = "8.7-rc-4"
java-vendor = "GraalVM Community"
java-jvmArguments = "--enable-preview"
java-addModules = "jdk.incubator.vector"
Expand All @@ -28,7 +28,7 @@ kotlinx-coroutines = "1.8.1-Beta"
kotlinx-datetime = "0.6.0-RC.2"
kotlinx-serialization = "1.6.3"
kotlinx-collections-immutable = "0.3.7"
kotlinx-lincheck = "2.27"
kotlinx-lincheck = "2.28"
kotlinx-benchmark = "0.4.8"
kotlinx-reflect-lite = "1.1.0"
zip-prefixer = "0.3.1"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-rc-3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-rc-4-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 34bd1db

Please sign in to comment.