Add import

Proprietary

Add an import statement to a Go compilation unit. No-op if the import is already present in a compatible form.

org.openrewrite.golang.AddImport

Required

The import path to add.

Optional

onlyIfReferencedBoolean

When true, add the import only if some identifier in the file already references the package via type attribution.

mod run . --recipe=org.openrewrite.golang.AddImport \ -P packagePath=fmt

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.