dqpwdai095465 2019-07-20 20:08 采纳率: 100%
浏览 975
已采纳

在IntelliJ中,即使启用了go模块集成,导入也不会加载

当将IntelliJ IDEA与Go插件或GoLand一起使用,并使用Go 1.11或更高版本时,可以通过转到首选项->语言和框架-> Go-> Go模块(vgo)并选中“启用Go模块”框来启用Go模块 (vgo)整合”。 当你有一个项目是由适当的初始化 go mod init因而就有一个 go.modgo.sum文件,它将在命令行中使用以下命令下载依赖项 go build or from IntelliJ by pressing the green play icon. 或者按下绿色的play图标就可以得到IntelliJ。 但是,到远程依赖项的导入语句可能仍然是红色的,即使它们似乎已经下载并出现在go.mod文件中

奇怪的是,go项目实际上是从命令行运行的,而不是从IntelliJ内部运行的。为什么是这样的,我该怎么做?

  • 写回答

1条回答 默认 最新

  • doujingao6210 2019-07-20 20:08
    关注

    The reason this approach does not work, has to do with the configuration in IntelliJ. That is why it will work from command line, just not in IntelliJ.

    There are two ways to fix this:

    1. Go into Preferences -> Languages & Frameworks -> Go -> Go Modules (vgo) and make sure the box 'Vendoring mode' is not checked.
    2. Make sure you have a folder called 'vendor' in your IntelliJ project. Now the box 'Vendoring mode' can be safely checked.

    With the first approach the dependencies defined in your go.mod file might be re-downloaded, for example when the go project is run from a place where these dependencies are not in the local package registry.

    With the second approach the dependencies are put in the 'vendor' folder and do not necessarily need to be re-downloaded, they are sort of made part of the project.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序