https://kotlinlang.org logo
#getting-started
Title
# getting-started
t

Tarun Chawla

06/10/2021, 6:57 AM
how to set the kotlin version in gradle file? This is my build.gradle.kts:
Copy code
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack

plugins {
  kotlin("multiplatform") version "1.5.10"
  kotlin("plugin.serialization") version "1.5.10"
  application
}

group = "tech.tarunchawla"
version = "0.0.1"

repositories {
  jcenter()
  mavenCentral()
  maven { url = uri("<https://dl.bintray.com/kotlin/kotlin-js-wrappers>") }
  maven { url = uri("<https://dl.bintray.com/kotlin/kotlinx>") }
  maven { url = uri("<https://dl.bintray.com/kotlin/ktor>") }
  maven("<https://dl.bintray.com/konform-kt/konform>")
}

kotlin {
  jvm {
    compilations.all {
      kotlinOptions.jvmTarget = "1.8"
    }
    testRuns["test"].executionTask.configure {
      useJUnit()
    }
    withJava()
  }
  js(LEGACY) {
    browser {
      binaries.executable()
      webpackTask {
        cssSupport.enabled = true
      }
      runTask {
        cssSupport.enabled = true
      }
      testTask {
        useKarma {
          useChromeHeadless()
          webpackConfig.cssSupport.enabled = true
        }
      }
    }
  }
  sourceSets {
    val commonMain by getting {}
    val commonTest by getting {
      dependencies {
        implementation(kotlin("test-common"))
        implementation(kotlin("test-annotations-common"))
      }
    }
    val jvmMain by getting {
      dependencies {
        implementation("io.ktor:ktor-server-netty:1.6.0")
        implementation("io.ktor:ktor-html-builder:1.6.0")
        implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
        implementation("io.ktor:ktor-gson:1.6.0")
        implementation("io.ktor:ktor-auth:1.6.0")
        implementation("io.ktor:ktor-auth-jwt:1.6.0")
        implementation("io.ktor:ktor-serialization:1.6.0")
        implementation("org.postgresql:postgresql:42.2.20")
        implementation("org.jetbrains.exposed:exposed-core:0.31.1")
        implementation("org.jetbrains.exposed:exposed-jdbc:0.31.1")
        implementation("org.jetbrains.exposed:exposed-java-time:0.31.1")
        implementation("com.auth0:java-jwt:3.10.3")
      }
    }
    val jvmTest by getting {
      dependencies {
        implementation(kotlin("test-junit"))
        implementation("org.xerial:sqlite-jdbc:3.34.0")
      }
    }
    val jsMain by getting {
      dependencies {
        implementation("io.ktor:ktor-client-js:1.6.0")
        implementation("io.ktor:ktor-client-serialization:1.6.0")
        implementation("org.jetbrains.kotlin-wrappers:kotlin-react:17.0.2-pre.206-kotlin-1.5.10")
        implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:17.0.2-pre.206-kotlin-1.5.10")
        implementation(npm("react", "17.0.2"))
        implementation(npm("react-dom", "17.0.2"))
        implementation("org.jetbrains.kotlin-wrappers:kotlin-styled:5.3.0-pre.206-kotlin-1.5.10")
        implementation(npm("styled-components", "~5.3.0"))
        implementation("org.jetbrains.kotlin-wrappers:kotlin-react-router-dom:5.2.0-pre.206-kotlin-1.5.10")
        implementation("org.jetbrains.kotlin-wrappers:kotlin-redux:4.0.5-pre.206-kotlin-1.5.10")
        implementation("org.jetbrains.kotlin-wrappers:kotlin-react-redux:7.2.3-pre.206-kotlin-1.5.10")
        implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
        implementation("io.konform:konform-js:0.2.0")
      }
    }
    val jsTest by getting {
      dependencies {
        implementation(kotlin("test-js"))
      }
    }
  }
}

application {
  mainClass.set("MainKt")
}

tasks.withType<Jar> {
  manifest {
    attributes["Main-Class"] = "MainKt"
  }
  from(sourceSets.main.get().output)

  dependsOn(configurations.runtimeClasspath)
  from({
    configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
  })
}

tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack") {
  outputFileName = "output.js"
}

tasks.getByName<Jar>("jvmJar") {
  dependsOn(tasks.getByName("jsBrowserProductionWebpack"))
  val jsBrowserProductionWebpack = tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack")
  from(File(jsBrowserProductionWebpack.destinationDirectory, jsBrowserProductionWebpack.outputFileName))
}

tasks.getByName<JavaExec>("run") {
  dependsOn(tasks.getByName<Jar>("jvmJar"))
  classpath(tasks.getByName<Jar>("jvmJar"))
}
s

Sourabh Rawat

06/10/2021, 9:29 PM
In the plugins block. You have currently set it to 1.5.10
t

Tarun Chawla

06/11/2021, 7:43 AM
ok thank you.
16 Views