AWS CodeBuild Buildspec.yml example for Gradle and a Micronaut Application

I use Gradle as my build tool of choice for my Micronaut applications.

I often use AWS CodeBuild as my continuous integration service.

I use such a buildspec.yml file:

A buildspec is a collection of build commands and related settings, in YAML format, that CodeBuild uses to run a build.

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11 
  build:
    commands:
      - ./gradlew build --scan
  post_build:
    finally:
      - rm -f  /root/.gradle/caches/modules-2/modules-2.lock
      - rm -fr /root/.gradle/caches/*/plugin-resolution/
artifacts:
  files:
    - '*-all.jar'
  base-directory: 'build/libs'
cache:
  paths:
    - '/root/.gradle/caches/**/*' 
    - '/root/.gradle/wrapper/**/*'

My builds include the Gradle Scan plugin.

Because of that I can include the argument --scan which publishes a build scan. An available build scan makes easy to investigate build failures (access tests reports etc).

Tags: #micronaut #aws #codebuild