Run Maven Command

Action ID: maven
NPM Package:

@gcornacchia/backstage-plugin-scaffolder-maven-actions

Description

Executes a specified Maven command in the designated working directory within the scaffolder workspace.

Input Schema

PropertyTypeDescriptionRequired
argsarray-
commandstringThe maven command to run
workingDirectorystringWorking directory within the scaffolder workspace to execute the command in

Output Schema

No output schema defined for this action.

Usage Examples

Build and package a Java service

Runs mvn clean package in the workspace root to compile and package the service. Use this right after fetching sources with fetch:template.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: https://github.com/acme-org/java-service-template/archive/main.tar.gz
      targetPath: .
      values:
        name: ${{ parameters.componentName }}
        javaVersion: 17

  - id: maven-build
    action: maven
    input:
      command: clean package
      workingDirectory: .
      args:
        - -DskipTests=true
        - -B

Run tests with a Maven profile in a submodule

Executes mvn test in a specific subdirectory with a selected profile. Use this when the template generates a multi-module project and you want to test one module.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: https://github.com/acme-org/multi-module-java/archive/main.tar.gz
      targetPath: .
      values:
        rootPackage: com.acme.payments

  - id: module-tests
    action: maven
    input:
      command: test
      workingDirectory: services/payment-service
      args:
        - -P ${{ parameters.mavenProfile }}
        - -Dspring.profiles.active=${{ parameters.mavenProfile }}
        - -B

Build an OCI image using Spring Boot plugin

Runs the Spring Boot build-image goal to create a container image. Use this after building the JAR to produce a deployable image.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: https://github.com/acme-org/spring-boot-service/archive/main.tar.gz
      targetPath: .
      values:
        name: ${{ parameters.componentName }}

  - id: build-image
    action: maven
    input:
      command: spring-boot:build-image
      workingDirectory: .
      args:
        - -DskipTests=true
        - -Dspring-boot.build-image.imageName=ghcr.io/acme/${{ parameters.componentName }}:latest
        - -B

Deploy artifacts to an internal Maven repository

Runs mvn deploy with a custom settings file and repository configuration. Use this to publish artifacts to Nexus or Artifactory from the scaffolder.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: https://github.com/acme-org/inventory-service/archive/main.tar.gz
      targetPath: .
      values:
        name: inventory-service

  - id: maven-deploy
    action: maven
    input:
      command: deploy
      workingDirectory: services/inventory-service
      args:
        - -DskipTests=true
        - -s .mvn/settings.xml
        - -DaltDeploymentRepository=internal-releases::default::https://nexus.example.com/repository/maven-releases/
        - -B

Build selected modules with parallelization

Builds only specific modules with mvn clean install using -pl and enables parallel builds. Use this to speed up multi-module builds and avoid building everything.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: https://github.com/acme-org/multi-module-java/archive/main.tar.gz
      targetPath: .
      values:
        modules:
          - service-a
          - service-b

  - id: selective-build
    action: maven
    input:
      command: clean install
      workingDirectory: .
      args:
        - -pl
        - service-a,service-b
        - -am
        - -T
        - 1C
        - -Drevision=${{ parameters.version }}
        - -DskipTests=${{ parameters.skipTests }}
        - -B