vscode-kotlin icon indicating copy to clipboard operation
vscode-kotlin copied to clipboard

Issues with Gradle Kotlin DSL

Open jul1u5 opened this issue 4 years ago • 6 comments

Thanks for creating this extension!

Describe the bug I want to use Kotlin DSL to configure Gradle build for a project which uses Java. However, the extension produces a lot of errors.

To Reproduce Here is my build.gradle.kts file:

plugins {
    java
    application
}

repositories {
    jcenter()
}

dependencies {
    implementation("junit:junit:4.13")
    testImplementation("junit:junit:4.13")
}

configurations {
    implementation {
        resolutionStrategy.failOnVersionConflict()
    }
}

sourceSets {
    main {
        java.setSrcDirs(listOf("src"))
    }
    test {
        java.setSrcDirs(listOf("src"))
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

application {
    mainClassName = "app.App"
}

val test by tasks.getting(Test::class) {
    useJUnitPlatform()
}

Here are the errors: Kotlin errors

Extension version 0.2.11

jul1u5 avatar Apr 20 '20 21:04 jul1u5

Please try adding the option "kotlin.compiler.jvm.target": "1.8" to your VSCode settings.

fwcd avatar Jun 30 '20 21:06 fwcd

Thanks for the response. I added the option and restarted the language server. JVM errors have disappeared, but the extension still seems to not understand some of the Gradle functions:

image

NOTE: The code has changed a little bit since I posted it here

jul1u5 avatar Jun 30 '20 21:06 jul1u5

Same issue here. Didn't run into it until I enabled this extension, and changing Kotlin › Compiler › Jvm: Target from "default" to 1.8 for both User and Workspace as mentioned above still gives red error lines in the gradle.build.kts file.

cmitchell avatar Jun 07 '21 12:06 cmitchell

Same issue...

Baneeishaque avatar Jul 31 '21 10:07 Baneeishaque

Same Issue aswell in settings.gradle.kts as in build.gradle.kts for a gradle init project with Kotlin and Kotlin DSL without any changes made.

image

Could developing in WSL be part of the problem? The Extension is installed inside WSL

image

ptrckdev avatar Nov 26 '22 16:11 ptrckdev

@ptrckdev No, it's not just WSL. I have the same issue. I'm on Fedora 38 but Linux shouldn't be the issue. I think it's just that the plugin isn't designed to work with Kotlin DSL files. I was really hoping it would work but at the moment, that doesn't seem possible. In my opinion, Kotlin DSL support is even more useful than Kotlin project support since Gradle now prefers Kotlin DSL over Groovy DSL. For the time being, I think I'll just use IntelliJ IDEA for my Java/Kotlin work and use VSCode for the other stuff.

megabyte6 avatar Sep 13 '23 17:09 megabyte6