IntelliJ IDEA 2021.1 Help

Build constraints and vendoring

Build constraints and vendoring mode are tools that you can use for fine-tuning of your build process. With build constraints, you define rules under which files are included in the package. With the vendoring mode enabled, you build your application only with dependency packages that are stored inside your project. So, you can include only a specific set of files in your package and use the dependencies that you locally modified or patched.

Build constraints

A build constraint or a build tag is a line comment that lists the conditions under which a file is included in the package. These tags can describe an operating system, architecture, a Go version, a compiler, CGO support, or any other requirements for a target system. In the following example, we declare that this file is for the target system that has the following requirements: Linux, the AMD64 architecture, the 1.12 Go version, and no CGO support.

Build constraints

IntelliJ IDEA can use these constraints to decide what files must be ignored during validation, resolving, and symbol suggestions. If the file does not satisfy requirements of the target system, IntelliJ IDEA displays a notification.

Notification about build constraints

Configure build constraints for your project

Options that you define in settings describe your target system for the project.

  1. Open settings (Ctrl+Alt+S) and navigate to Languages & Frameworks | Go | Build tags & Vendoring.

  2. From drop-down lists, select expected values for the target system. If you have any custom tags, specify them in the Custom tags field (use a space between tags as a separator).

  3. Click OK.

    Configure build constraints for your project

Vendoring

With the vendoring mode enabled, you build your application only with dependency packages that are stored inside your project under the vendor directory. In this mode, Go commands ignore dependency descriptions in go.mod and assume that the vendor directory holds the correct copies of dependencies. By default, when you use Go modules, the vendor directory is ignored during the build.

In Go 1.14 RC, automatic vendoring mode became a built-in Go feature. Starting from Go 1.14 RC, IntelliJ IDEA also enables automatic vendoring mode by default. You cannot disable this setting.

Automatic vendoring mode in Go 1.14

For earlier Go versions, you can control automatic vendoring by using the Enable vendoring support automatically checkbox. When the checkbox is selected, automatic vendoring is enabled. So, if you add the vendor directory to the module, the IDE uses it. If you remove the directory, IntelliJ IDEA uses the global Go Modules cache.

Automatic vendoring mode in Go 1.13 and earlier versions

Toggle vendoring mode

You can toggle vendoring mode in Go versions 1.13 and earlier. In Go 1.14 RC, automatic vendoring mode became a built-in Go feature.

  1. Open settings by pressing Ctrl+Alt+S and navigate to Languages & Frameworks | Go | GOROOT.

  2. From the GOROOT list, select the Go version 1.13 or earlier.

  3. Click the Go Modules menu item.

  4. Clear or select the Enable vendoring support automatically checkbox and click OK.

    Automatic vendoring mode in Go 1.13 and earlier versions

Enable vendoring support for Go 1.5

If you enable vendoring support for Go 1.5, IntelliJ IDEA resolves and completes symbols according to Go Vendoring Experiment Proposal.

  1. Open settings (Ctrl+Alt+S) and navigate to Languages & Frameworks | Go | GOROOT. Ensure that GOROOT uses Go 1.5.

  2. Navigate to Languages & Frameworks | Go | Build tags & Vendoring.

  3. From the Enable vendoring list, select Enable.

Last modified: 28 May 2021