Copier Maven Goals
This guide covers the copier-based Maven goals for managing configuration files from templates using the Copier CLI tool.
Quick Reference
| Goal | Usage | Description |
|---|---|---|
|
|
Initialize files from any template |
|
|
Update files from any template |
Overview
The NGSS Filegen Maven Plugin includes support for Copier, a tool for rendering project templates. Copier allows you to initialize and update configuration files from Git-based templates while preserving your local modifications.
The plugin provides generic goals that work with any template, including DevOps, Backstage, and custom templates.
Prerequisites
Install Copier
Before using the copier goals, you must have Copier and its dependencies installed on your system:
brew install python # if needed
brew install pipx
pipx install copier
pipx inject copier copier-template-extensions
pipx ensurepath
Verify the installation:
copier --version
For more information, see the Copier documentation.
Template Repositories
The plugin supports template repositories including:
-
DevOps Template:
https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git -
Backstage Template:
https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-backstage-template.git -
Spring MCP Template:
https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-spring-mcp-template.git -
Custom templates: Any Git repository with a Copier template
Available Goals
copier-init
Initialize configuration files from any template.
mvn filegen:copier-init -Dcopier.template=devops
mvn filegen:copier-init -Dcopier.template=backstage
mvn filegen:copier-init -Dcopier.template=spring-mcp
This goal:
-
Runs Copier in "copy" mode to initialize files
-
Prompts you interactively for configuration values
-
Generates a
.copier-answers/<template>.yamlfile with your responses -
Creates the configuration files in your project
Properties:
| Property | Default | Description |
|---|---|---|
|
(required) |
Template name ( |
|
|
Skip execution of the goal |
|
(auto-resolved) |
Custom template Git URL (overrides default) |
|
|
Destination directory |
|
|
Whether to trust the template |
|
(latest) |
Template version/tag to use |
Example with custom template:
mvn filegen:copier-init \
-Dcopier.template=custom \
-Dcopier.templateUrl=https://example.com/my-template.git
Example with specific version:
mvn filegen:copier-init \
-Dcopier.template=devops \
-Dcopier.version=v2.0.0
copier-update
Update configuration files from any template.
mvn filegen:copier-update -Dcopier.template=devops
mvn filegen:copier-update -Dcopier.template=backstage
mvn filegen:copier-update -Dcopier.template=spring-mcp
This goal:
-
Runs Copier in "update" mode to refresh files
-
Uses answers from
.copier-answers/<template>.yaml -
Prompts only for new or changed questions (with
--skip-answered) -
Preserves your local modifications
Properties:
| Property | Default | Description |
|---|---|---|
|
(required for single template) |
Template name ( |
|
(optional) |
List of templates to update (e.g., |
|
|
Skip execution of the goal |
|
(auto-resolved) |
Custom answers file path |
|
|
Destination directory |
|
|
Whether to trust the template |
|
|
Skip previously-answered prompts |
|
(latest) |
Template version/tag to use |
|
(optional) |
Override version for specific template (e.g., |
Example with specific version:
mvn filegen:copier-update -Dcopier.template=devops -Dcopier.version=v2.1.0
Example updating multiple templates:
mvn filegen:copier-update -Dcopier.updateTemplates=devops,backstage
Example with auto-discovery of answers files in .copier-answers directory:
mvn filegen:copier-update
Example with per-template version overrides:
mvn filegen:copier-update -Dcopier.updateTemplates=devops,backstage \
-Dcopier.devops.version=v3.5.0 \
-Dcopier.backstage.version=v2.1.0
copier
Unified goal that supports both init and update modes.
Initialize:
mvn filegen:copier -Dcopier.init -Dcopier.template=devops
Update:
mvn filegen:copier -Dcopier.update -Dcopier.template=backstage
Properties:
| Property | Default | Description |
|---|---|---|
|
|
Run in init mode (exactly one of init/update required) |
|
|
Run in update mode (exactly one of init/update required) |
|
(required) |
Template name |
|
|
Skip execution |
|
(auto-resolved) |
Custom template URL |
|
|
Destination directory |
|
|
Trust the template |
|
(latest) |
Template version |
Workflow Examples
Initial Project Setup
When setting up a new project:
-
Initialize DevOps configuration:
mvn filegen:copier-init -Dcopier.template=devops -
Initialize Backstage configuration:
mvn filegen:copier-init -Dcopier.template=backstage -
Commit the generated files and answers files:
git add .copier-answers/ git commit -m "Initialize DevOps and Backstage configurations"
Updating to Latest Template Version
To update your project with the latest template changes:
-
Update a single template:
mvn filegen:copier-update -Dcopier.template=devops -
Or update all templates at once:
mvn filegen:copier-update(This will update all templates that have answers files in
.copier-answers/) -
Review changes and commit:
git diff git add -A git commit -m "Update to latest template versions"
Updating to Specific Template Version
To update to a specific version of a template:
mvn filegen:copier-update -Dcopier.template=devops -Dcopier.version=v2.0.0
Or use per-template version overrides:
mvn filegen:copier-update -Dcopier.devops.version=v3.5.0
Answers Files
Copier stores your configuration answers in YAML files under .copier-answers/:
-
.copier-answers/devops.yaml- DevOps template answers -
.copier-answers/backstage.yaml- Backstage template answers
These files should be committed to version control as they:
-
Record your configuration choices
-
Enable reproducible updates
-
Allow team members to update consistently
Skip Flags
All copier goals respect the following skip flags:
-
skipAll- Global skip flag for all filegen goals -
copier.skip- Skip flag for copier goals
Example:
# Skip copier goal execution
mvn filegen:copier-init -Dcopier.template=devops -Dcopier.skip=true
# Skip all filegen goals
mvn install -DskipAll=true
Trust Flag
The trust flag controls whether Copier trusts the template to execute tasks and migrations. By default, this is set to true for convenience.
Only use templates from trusted sources. The --trust flag allows templates to execute arbitrary code.
|
To disable trust for security:
mvn filegen:copier-init -Dcopier.templateUrl=https://some-random-template.org/templates.git -Dcopier.trust=false
Troubleshooting
Copier Not Found
If you see an error about copier not being found:
-
Verify Copier is installed:
copier --version -
Ensure it’s in your PATH:
which copier -
Install if missing:
pipx install copier pipx inject copier copier-template-extensions pipx ensurepath
Best Practices
-
Commit answers files: Always commit
.copier-answers/to version control -
Regular updates: Periodically update templates to get bug fixes and improvements
-
Review changes: Always review template updates before committing
-
Pin versions: Use specific versions in CI/CD for reproducibility
-
Test updates: Test template updates in a feature branch first