Skip to content

Generate Executor

Terminal window
nx run my-go-app:generate

Note: Use nx run <project>:generate instead of nx generate <project> to avoid conflicts with Nx’s native generator commands.

OptionTypeDefaultDescription
envobject-Environment variables to set when running the executor
flagsstring[]-Flags to pass to the go generate command
{
"executor": "@naxodev/gonx:generate",
"cache": true,
"dependsOn": ["^generate"],
"inputs": ["{projectRoot}/go.mod", "{projectRoot}/go.sum", "{projectRoot}/**/*.{go}"]
}
Terminal window
nx run my-go-app:generate
Terminal window
nx run my-go-app:generate --flags=-v
Terminal window
nx run my-go-app:generate --flags=-v --flags=-x

Generate with custom environment variables

Section titled “Generate with custom environment variables”
Terminal window
nx run my-go-app:generate --env.GOOS=linux --env.GOARCH=amd64
  • The generate executor is cacheable, so subsequent runs with the same inputs will be faster
  • Uses the official go generate command in the background
  • The generate executor automatically runs before build and test operations due to dependency configuration
  • The command searches for //go:generate directives in all Go files within the project and its subdirectories
  • Generated files should be committed to version control if they are needed for builds
  • The executor runs go generate ./... to process all packages in the project tree
  • Important: Always use nx run <project>:generate syntax to avoid conflicts with Nx’s nx generate command for generators