如何配置VScode以调试gradle/Kotlin项目?

2exbekwf  于 2023-03-03  发布在  Kotlin
关注(0)|答案(1)|浏览(544)

目前正在尝试使用devcontainer整合VScode中的后端和前端开发工作流,而不是InteliJ用于后端和VScode用于前端,同时考虑使用Codespace/Gitpod,目标是简化整个堆栈的调试。
我在VScode中阅读了多个Gradle教程,最终得到了一些可以构建和运行的东西,但是调试器不起作用,我没有找到任何教程来处理这一部分。
到目前为止,最好的结果是使用以下任务和Gradle扩展VScode:

{
            "type": "gradle",
            "id": "/workspaces/mycode/serverrunMyCode",
            "script": "run",
            "description": "Runs this project as a JVM application",
            "group": "application",
            "project": "MyCode",
            "buildFile": "/workspaces/mycode/server/build.gradle.kts",
            "rootProject": "MyCode",
            "projectFolder": "/workspaces/mycode/server",
            "workspaceFolder": "/workspaces/mycode/server",
            "args": "",
            "javaDebug": true,
            "problemMatcher": [
                "$gradle"
            ],
            "label": "Server Debug"
        }

服务器通过VScode正确构建和运行,但调试器不工作。
我已经尝试使用Kotlin扩展和以下启动设置,但这里出现了缺少依赖项的问题

"configurations": [
        {
            "type": "kotlin",
            "request": "launch",
            "name": "Kotlin Launch",
            "projectRoot": "${workspaceFolder}",
            "mainClass": "io.mycode.ServerKt"
        }
    ]

依赖关系错误:

[INFO] main      Connected to client
[INFO] async1    Resolving dependencies for 'server' through Gradle's CLI using tasks [kotlinLSPProjectDeps]...
[WARN] async1    Could not resolve classpath using Gradle: ClassLoader.getSystemResourceAsStream(scriptName) must not be null
[INFO] async1    Could not resolve kotlin-stdlib using Maven: Cannot invoke "java.nio.file.Path.getFileSystem()" because "path" is null
[INFO] async1    Successfully resolved kotlin-stdlib using Gradle
[INFO] async1    Starting JVM debug session with main class io.mycode.ServerKt
Error: Unable to initialize main class io.mycode.ServerKt
Caused by: java.lang.NoClassDefFoundError: mu/KLogger
[INFO] eventBus  Sent exit event
[INFO] async0    Exiting JDI session

所以我的问题很简单:VScode使用gradle/Kotlin项目的工作配置是什么?包括调试。
谢谢

gzszwxb4

gzszwxb41#

我遇到过一个非常类似的问题,通过从源代码编译Kotlin调试适配器并配置Kotlin VSCode扩展以使用编译后的版本解决了这个问题。

相关问题