build.gradle.kts Gradle Kotlin DSL example
See original GitHub issueCould you please provide a Gradle example using the Kotlin DSL? I am trying this:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.Coroutines
buildscript {
val kotlin_version = "1.3.10"
repositories {
mavenCentral()
}
dependencies {
classpath(kotlin("gradle-plugin", kotlin_version))
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlin_version")
}
}
plugins {
kotlin("jvm") version "1.3.10"
"kotlinx-serialization"
}
dependencies {
compile(kotlin("stdlib-jdk8"))
compile(kotlin("reflect"))
testCompile(kotlin("test"))
testCompile(kotlin("test-junit"))
compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.5")
testCompile("io.kotlintest:kotlintest-runner-junit5:3.1.7")
compile("redis.clients:jedis:2.9.0")
compile("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.9.0")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
repositories {
mavenCentral()
maven (url="https://kotlin.bintray.com/kotlinx" )
}
But when I try to compile the example like JSON.stringify(Data.serializer(), Data(42))
, I get the error:
e: src/main/kotlin/HelloWorld.kt: (260, 45): Unresolved reference: serializer
> Task :compileKotlin FAILED
FAILURE: Build failed with an exception.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Gradle Kotlin DSL Primer
Everything you can read in a Kotlin DSL script is Kotlin code compiled and executed by Gradle. Many of the objects, functions and...
Read more >kotlin-dsl-samples/build.gradle.kts at master · gradle ... - GitHub
Samples builds using the Gradle Kotlin DSL. Contribute to gradle/kotlin-dsl-samples development by creating an account on GitHub.
Read more >A deep dive into an initial Kotlin build.gradle.kts - Medium
This is the third article in a series about building a Kotlin project with Gradle configured using the Kotlin DSL. In the previous...
Read more >Kotlin DSL for Gradle - Baeldung
2. How to Create a Kotlin DSL Script ·.gradle.kts instead of .gradle for our build scripts ·.settings.gradle.kts instead of .settings.gradle for ...
Read more >The New Way of Writing Build Gradle with Kotlin DSL
the basic thing when you change Gradle using Kotlin script is the use of single-quotes to double-quotes. For minSdkVersion and targetSdkVersion is function...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Btw, https://github.com/Kotlin/kotlinx.serialization#gradle-with-plugins-block actually is Gradle Kotlin DSL example so I suppose this can be closed.
Here’s how I got it working:
and then in the build.gradle.kts file I included it like this: