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

copier-init

mvn filegen:copier-init

Initialize all standard templates (devops, backstage)

copier-init

mvn filegen:copier-init -Dcopier.template=<name>

Initialize a specific template

copier-update

mvn filegen:copier-update

Update all templates (auto-detect from .copier-answers/)

copier-update

mvn filegen:copier-update -Dcopier.template=<name>

Update a specific 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:

Available Goals

copier-init

Initialize configuration files from templates.

Initialize all standard templates (devops, backstage):

# Maven
mvn filegen:copier-init

# Copier CLI (run once per template)
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git . --trust
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-backstage-template.git . --trust

Initialize a specific template:

# Maven
mvn filegen:copier-init -Dcopier.template=devops
mvn filegen:copier-init -Dcopier.template=backstage
mvn filegen:copier-init -Dcopier.template=spring-mcp

# Copier CLI
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git . --trust
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-backstage-template.git . --trust
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-spring-mcp-template.git . --trust

This goal:

  • Runs Copier in "copy" mode to initialize files

  • Prompts you interactively for configuration values

  • Generates a .copier-answers/<template>.yaml file with your responses

  • Creates the configuration files in your project

Properties:

Property Default Description

copier.template

(optional)

Template name (devops, backstage, or spring-mcp). If not specified, initializes all standard templates (devops, backstage).

copier.skip

false

Skip execution of the goal

copier.templateUrl

(auto-resolved)

Custom template Git URL (overrides default)

copier.destination

.

Destination directory

copier.trust

true

Whether to trust the template

copier.version

(latest)

Template version/tag to use

Example with custom template:

# Maven
mvn filegen:copier-init \
  -Dcopier.template=custom \
  -Dcopier.templateUrl=https://example.com/my-template.git

# Copier CLI
copier copy https://example.com/my-template.git . --trust

Example with specific version:

# Maven
mvn filegen:copier-init \
  -Dcopier.template=devops \
  -Dcopier.version=v2.0.0

# Copier CLI
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git . --trust --vcs-ref=v2.0.0

copier-update

Update configuration files from any template.

# Maven
mvn filegen:copier-update -Dcopier.template=devops
mvn filegen:copier-update -Dcopier.template=backstage
mvn filegen:copier-update -Dcopier.template=spring-mcp

# Copier CLI
copier update -a .copier-answers/devops.yaml
copier update -a .copier-answers/backstage.yaml
copier update -a .copier-answers/spring-mcp.yaml

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

copier.template

(required for single template)

Template name (devops, backstage, or spring-mcp)

copier.updateTemplates

(optional)

List of templates to update (e.g., devops,backstage)

copier.skip

false

Skip execution of the goal

copier.answersFile

(auto-resolved)

Custom answers file path

copier.destination

.

Destination directory

copier.trust

true

Whether to trust the template

copier.skipAnswered

true

Skip previously-answered prompts

copier.version

(latest)

Template version/tag to use

copier.<template>.version

(optional)

Override version for specific template (e.g., copier.devops.version=v3.5.0)

Example with specific version:

# Maven
mvn filegen:copier-update -Dcopier.template=devops -Dcopier.version=v2.1.0

# Copier CLI
copier update -a .copier-answers/devops.yaml --vcs-ref=v2.1.0

Example updating multiple templates:

# Maven
mvn filegen:copier-update -Dcopier.updateTemplates=devops,backstage

# Copier CLI (run once per template)
copier update -a .copier-answers/devops.yaml
copier update -a .copier-answers/backstage.yaml

Example with auto-discovery of answers files in .copier-answers directory:

# Maven
mvn filegen:copier-update

# Copier CLI (run once per answers file)
for f in .copier-answers/*.yaml; do copier update -a "$f"; done

Example with per-template version overrides:

# Maven
mvn filegen:copier-update -Dcopier.updateTemplates=devops,backstage \
  -Dcopier.devops.version=v3.5.0 \
  -Dcopier.backstage.version=v2.1.0

# Copier CLI
copier update -a .copier-answers/devops.yaml --vcs-ref=v3.5.0
copier update -a .copier-answers/backstage.yaml --vcs-ref=v2.1.0

copier

Unified goal that supports both init and update modes.

Initialize:

# Maven
mvn filegen:copier -Dcopier.init -Dcopier.template=devops

# Copier CLI
copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git . --trust

Update:

# Maven
mvn filegen:copier -Dcopier.update -Dcopier.template=backstage

# Copier CLI
copier update -a .copier-answers/backstage.yaml

Properties:

Property Default Description

copier.init

false

Run in init mode (exactly one of init/update required)

copier.update

false

Run in update mode (exactly one of init/update required)

copier.template

(required)

Template name

copier.skip

false

Skip execution

copier.templateUrl

(auto-resolved)

Custom template URL

copier.destination

.

Destination directory

copier.trust

true

Trust the template

copier.version

(latest)

Template version

Workflow Examples

Initial Project Setup

When setting up a new project:

  1. Initialize DevOps configuration:

    # Maven
    mvn filegen:copier-init -Dcopier.template=devops
    
    # Copier CLI
    copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git . --trust
  2. Initialize Backstage configuration:

    # Maven
    mvn filegen:copier-init -Dcopier.template=backstage
    
    # Copier CLI
    copier copy https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-backstage-template.git . --trust
  3. 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:

  1. Update a single template:

    # Maven
    mvn filegen:copier-update -Dcopier.template=devops
    
    # Copier CLI
    copier update -a .copier-answers/devops.yaml
  2. Or update all templates at once:

    # Maven
    mvn filegen:copier-update
    
    # Copier CLI
    for f in .copier-answers/*.yaml; do copier update -a "$f"; done

    (This will update all templates that have answers files in .copier-answers/)

  3. 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:

# Maven
mvn filegen:copier-update -Dcopier.template=devops -Dcopier.version=v2.0.0

# Copier CLI
copier update -a .copier-answers/devops.yaml --vcs-ref=v2.0.0

Or use per-template version overrides:

# Maven
mvn filegen:copier-update -Dcopier.devops.version=v3.5.0

# Copier CLI
copier update -a .copier-answers/devops.yaml --vcs-ref=v3.5.0

Updating Multiple Templates with Different Versions

To update multiple templates with specific versions:

# Maven
mvn filegen:copier-update -Dcopier.updateTemplates=devops,backstage \
  -Dcopier.devops.version=v3.5.0 -Dcopier.backstage.version=v2.1.0

# Copier CLI
copier update -a .copier-answers/devops.yaml --vcs-ref=v3.5.0
copier update -a .copier-answers/backstage.yaml --vcs-ref=v2.1.0

Using Custom Template Repository

To use a custom or forked template repository:

# Maven
mvn filegen:copier-init -Dcopier.template=custom -Dcopier.templateUrl=https://example.com/my-custom-template.git

# Copier CLI
copier copy https://example.com/my-custom-template.git . --trust

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:

  1. Verify Copier is installed:

    copier --version
  2. Ensure it’s in your PATH:

    which copier
  3. Install if missing:

    pipx install copier
    pipx inject copier copier-template-extensions
    pipx ensurepath

Answers File Not Found

If you see "Skipping…​ Answers file has not been initialized":

  1. Make sure you’ve run the init goal first:

    mvn filegen:copier-init -Dcopier.template=devops
  2. Verify the answers file exists:

    ls -la .copier-answers/

Template Version Issues

To check available template versions:

git ls-remote --tags https://coderepo.mobilehealth.va.gov/scm/ckm/ngss-devops-template.git

Best Practices

  1. Commit answers files: Always commit .copier-answers/ to version control

  2. Regular updates: Periodically update templates to get bug fixes and improvements

  3. Review changes: Always review template updates before committing

  4. Pin versions: Use specific versions in CI/CD for reproducibility

  5. Test updates: Test template updates in a feature branch first