fwcd / kotlin-debug-adapter

Kotlin/JVM debugging for any editor/IDE using the Debug Adapter Protocol
MIT License
117 stars 23 forks source link

How to make this work? #7

Open Spenhouet opened 5 years ago

Spenhouet commented 5 years ago

I'm unable to make this work. The instruction on this GitHub page are not very helpful.

I configured the following tasks (tasks.json):

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "backend: start",
            "type": "shell",
            "command": "./gradlew bootRun",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            },
            "problemMatcher": []
        },
        {
            "label": "backend: build",
            "type": "shell",
            "command": "./gradlew clean build",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            },
            "problemMatcher": []
        }
    ]
}

Both work great.

I also configured a launch configuration (launch.json):

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "kotlin",
            "request": "launch",
            "name": "Kotlin Launch",
            "projectRoot": "${workspaceFolder}",
            "mainClass": "ApiApplicationKt",
            "preLaunchTask": "backend: build"
        }
    ]
}

In my build.gradle I configured the following options:

buildscript {
    ext {
        kotlin_version = "1.3.0"
        ...
    }

    repositories {
        mavenCentral()
        google()
        jcenter()
        gradlePluginPortal()
    }

    dependencies {
        ....
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}")
    }
}

apply plugin: "kotlin"
apply plugin: "kotlin-spring"
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"
apply plugin: 'application'

group = "io.realworld"
version = "0.0.1-SNAPSHOT"
description = """api"""
mainClassName = "ApiApplicationKt"
sourceCompatibility = 1.8
targetCompatibility = 1.8

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

repositories {
    mavenCentral()
    google()
    jcenter()
    gradlePluginPortal()
}

dependencies {
    compile group: "org.jetbrains.kotlin", name: "kotlin-gradle-plugin", version: "${kotlin_version}"
    compile group: "org.jetbrains.kotlin", name: "kotlin-stdlib-jdk8", version: "${kotlin_version}"
    compile group: "org.jetbrains.kotlin", name: "kotlin-reflect", version: "${kotlin_version}"
    ....
}

When I try to launch the launch configuration I only get a

java.lang.ClassNotFoundException: ApiApplicationKt

Is my configure okay? What else could I have done wrong to get debugging working with kotling and vs code?

Ps. I wish there would be a simple example for tasks.json, launch.json, ... in the README of this project.

fwcd commented 5 years ago

@Spenhouet Your launch configuration looks fine. Are you working in a multi-directory workspace? In this case, you might need to specify the project directory rather than the workspace path:

"projectRoot": "${workspaceFolder}/name_of_your_project_folder",

Furthermore, this repository contains working launch.json and tasks.json files that launch this project; these can be used for reference purposes too.

The Usage section in the README-file intentionally contains a low-level description of the adapter's interface to allow any tool (not just VSCode) to hook into this debugger.