IntelliJ IDEA 2023.2 Help

Go workspaces

Go workspaces help you to work with several modules in your project. When you create a go.work file, Go runs through the list of modules listed in the workspace, and creates a single list of dependencies. If go.mod files have replace directives, Go will also take them into account. A generated single dependency list is applied to all the modules listed in the workspace.

When you create a go.work file, IntelliJ IDEA automatically adds all the modules in the project.

Create a workspace

  • Right-click the parent directory of your project and navigate to New | Go Workspace File.

Also, you can now generate go.work from go.mod if you have replace directives there.

Generate 'go.work' by using 'replace' directives

  • Place the caret at a replace directive, press Alt+Enter and select the Generate 'go.work' using 'replace' directives quick-fix.

    The underlying inspection that detects replace directives has the Warning severity and highlighting, meaning the relevant code is shown in a yellow box and the yellow warning triangle is shown in the top-right corner in the editor window.

    There may be no warning, however. If a generated workspace includes Go modules that are not replaced in the original go.mod, the warning is not shown due to possible side effects caused by migration.

Merge several use directives into one directive

  • Click a use directive, press Alt+Enter, and select Merge multiple 'use' directives into one.

Last modified: 27 October 2022