Delve版本太老导致 Intellij IDEA 无法 debug GO程序的解决方案

2,240 阅读1分钟

趁热记录下,给未来的自己

前言

最近在学习golang, 在IDEA里配置了golang的开发环境,点运行没有问题,点debug,发现报错:

Version of Delve is too old for this version of Go (maximum supported version 1.13, suppress this error with --check-go-version=false)

记录下解决方案,给有需要的人

解决

方案1

Delve版本太老,说明delve存在,但是版本和当前的golang版本不匹配,那就更新下delve

$ go get -u github.com/go-delve/delve/cmd/dlv

但本地实测之后,报如下错误:

(代理已经设置为阿里云的地址:GOPROXY=https://mirrors.aliyun.com/goproxy/,direct)

go get: upgrading golang.org/x/sys@v0.0.0-20200930185726-fdedc70b468f: unrecognized import path "golang.org/x/sys": https fetch: Get "https://golang.org/x/sys?go-get=1": dial tcp 216.2
39.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

先不去探究为什么会报上面的错误吧。其实,这个方案的本质就是升级一下delve版本,让其与golang版本(本地是1.15)相匹配不就得了。所以变通下,直接去github上下载一个吧。

方案2

  1. 找到delve的github仓库

  2. 把仓库克隆到本地:git clone https://github.com/go-delve/delve.git

  3. 进入到cmd/dlv目录,运行go build, 会生成一个dlv.exe文件

  4. dlv.exe放到$GOPATH中,比如这里是:D:/go/bin/dlv.exe

  5. 打开IDEA -> help -> Edit Custom Properties, 输入 dlv.path=D:/go/bin/dlv.exe

  6. 重启IDEA即可