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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘