最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - How to add value to build.gradle.kts? - Stack Overflow

programmeradmin1浏览0评论

I am using IntelliJ IDEA Community Edition 2023.3.2. I tried to do the following:

val fullName = "Donn Felker"
println(fullName::class)

The output I got is:

class java.long.String (Kotlin reflection is not available)

According to Kotlin reflection is not available I need to add the following to the build.gradle:

compile ".jetbrains.kotlin:kotlin-reflect:$kotlin_version"

I can see the build.gradle.kts, but I don't know how to add a value in the file:

plugins {
    kotlin("jvm") version "1.9.21"
}

group = ".example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(".jetbrains.kotlin:kotlin-test")
}

tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(21)
}

I am using IntelliJ IDEA Community Edition 2023.3.2. I tried to do the following:

val fullName = "Donn Felker"
println(fullName::class)

The output I got is:

class java.long.String (Kotlin reflection is not available)

According to Kotlin reflection is not available I need to add the following to the build.gradle:

compile ".jetbrains.kotlin:kotlin-reflect:$kotlin_version"

I can see the build.gradle.kts, but I don't know how to add a value in the file:

plugins {
    kotlin("jvm") version "1.9.21"
}

group = ".example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(".jetbrains.kotlin:kotlin-test")
}

tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(21)
}
Share Improve this question edited Mar 29 at 17:43 jonrsharpe 122k30 gold badges268 silver badges475 bronze badges asked Mar 29 at 17:19 smalltownstorysmalltownstory 73 bronze badges 1
  • docs.gradle./current/userguide/… – jonrsharpe Commented Mar 29 at 17:44
Add a comment  | 

1 Answer 1

Reset to default 0

You can add the value into the `dependencies` section. For Kotlin DSL, you can do this:

dependencies {
    testImplementation(".jetbrains.kotlin:kotlin-test")
    implementation (libs.kotlin.reflect) // Add this to your file.
}

Don't fet to Sync Gradle after updating build.gradle.kts

发布评论

评论列表(0)

  1. 暂无评论