Spring Boot framework

The Spring Boot extension streamlines the process of building Spring Boot application rocks.

The extension packs and copies the Jar package file to the rock. By default, the system foundation, or base, is set as bare to generate a lightweight image.

Note

The Spring Boot extension is compatible with the bare and ubuntu@24.04 bases.

Project requirements

To use the Spring Boot Framework extension, there must be either:

  • a pom.xml file

  • a build.gradle file

in the root directory of the project. The project must not contain both files, otherwise the rock initialization will fail.

For the build process to execute correctly, the mvnw or gradlew wrapper must have executable permissions.

Maven or Gradle usage

The spring-boot-framework extension dynamically determines the plugin to use to build the rock. Depending on the presence of pom.xml or build.gradle file, the extension will use either the maven or gradle plugin, respectively.

rockcraft.yaml
# if pom.xml is present, use maven plugin
parts:
  spring-boot-framework/install-app:
    plugin: maven
    maven-use-wrapper: False # If mvnw file is present, True
rockcraft.yaml
# if build.gradle is present, use gradle plugin
parts:
  spring-boot-framework/install-app:
    plugin: gradle
    gradle-task: bootJar

Java version

By default, the spring-boot-framework uses default-jdk package to build the rock. Depending on the build-base, a different Java JDK version is used. To find out what Java version is used to pack the JAR, you can search the Ubuntu package archive.

The build-packages key specifies the Java version for the rock. For example:

rockcraft.yaml
parts:
  spring-boot-framework/install-app:
    build-packages:
      - openjdk-17-jdk # specify the Java package to use

Included or excluded files

If migrate or migrate.sh exist in the project’s root directory, they will be included in the rock’s /app directory by default.

The stage key of the spring-boot-framework/assets part specifies the files to be included or excluded from the rock upon rockcraft pack, following the app/<filename> notation. For example:

rockcraft.yaml
parts:
  spring-boot-framework/assets:
    stage:
      - app/migrate
      - app/migrate.sh
      - app/another_file_or_directory

The stage key supports glob patterns to define the list of files. See Filesets for the various ways you can specify files in your rock.

Adding the stage key to the project file overrides the default files to be included. Files are excluded from the rock by defining stage and omitting the file to be excluded.