MVN compile fails with java.lang.OutOfMemoryError: GC overhead limit exceeded

I have an action set up which triggers on push which results in a java.lang.OutOfMemoryError: GC overhead limit exceeded error.

The build executes both locally in my IDE and in Circle CI with no problems.

This is the yml:

name: Java CI with Maven

on: [push]

jobs:
build:
if: ${{ github.ref == ‘refs/heads/development’ }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-java@v2.1.0
with:
distribution: ‘adopt’ # See ‘Supported distributions’ for available options
java-version: ‘8’
- name: Compile with Maven
run: mvn -s common-functions/awh-settings.xml --batch-mode compile -e -X --file common-functions/pom.xml
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}

This is the error:
[INFO] Compiling 15310 source files to /home/runner/work/bm-common-functions/bm-common-functions/common-functions/target/classes

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project common-functions: Fatal error compiling: java.lang.OutOfMemoryError: GC overhead limit exceeded → [Help 1]

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project common-functions: Fatal error compiling

Any help would be greatly appreciated.

I have fixed this by adding the following:

env:
MAVEN_OPTS: ‘-Xmx3200m’

Maven was running out of memory during compilation.