Generate Executor
nx run my-go-app:generateNote: Use
nx run <project>:generateinstead ofnx generate <project>to avoid conflicts with Nx’s native generator commands.
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
| env | object | - | Environment variables to set when running the executor |
| flags | string[] | - | Flags to pass to the go generate command |
Default Inferred
Section titled “Default Inferred”{ "executor": "@naxodev/gonx:generate", "cache": true, "dependsOn": ["^generate"], "inputs": ["{projectRoot}/go.mod", "{projectRoot}/go.sum", "{projectRoot}/**/*.{go}"]}Examples
Section titled “Examples”Basic code generation
Section titled “Basic code generation”nx run my-go-app:generateGenerate with verbose output
Section titled “Generate with verbose output”nx run my-go-app:generate --flags=-vGenerate with multiple flags
Section titled “Generate with multiple flags”nx run my-go-app:generate --flags=-v --flags=-xGenerate with custom environment variables
Section titled “Generate with custom environment variables”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 generatecommand in the background - The generate executor automatically runs before build and test operations due to dependency configuration
- The command searches for
//go:generatedirectives 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>:generatesyntax to avoid conflicts with Nx’snx generatecommand for generators