Spring support available on Ubuntu
- Share on:
- X (formerly Twitter)

This blog is contributed by Vladimir Petko, a Software Engineer at Canonical.
The release of Plucky Puffin earlier this year introduced the availability of the devpack for Spring, a new snap that streamlines the setup of developer environments for Spring on Ubuntu.
In this blog, we’ll explain what devpacks are and provide an overview of what the devpack for Spring brings to users. Whether you’re a seasoned user of Spring, or want to explore what it can do, in this blog we’ll provide you with the overview you need to unlock the powerful functionality that the devpack for Spring offers.
Introducing devpacks
Devpacks are snaps with collections of tools that assist in setting up, maintaining and publishing software projects. They provide tooling such as linters and formatters to maintain source code and integrations with packaging tools such as Rockcraft to deploy applications to the containers and create a self-contained build environment for the applications. The intention of devpacks is to lower the barrier of entry for developers looking to build software according to the best practices.
What is devpack for Spring?
For those who aren’t familiar, Spring is a popular open-source Java framework designed to help developers build robust enterprise Java applications. According to a 2023 report by JetBrains, 72% of respondents reported using Spring as their framework of choice.
Experienced users may already be familiar with Spring CLI, a command line productivity tool that lowers the barrier to entry for starting a new Spring project, as well as for adding new features and performing day-to-day maintenance. It provides:
- A
boot start
command to bootstrap a new Spring project. - A
boot new
command to clone an existing project. - A
boot add
to merge the current project with an existing one. - The ability to declare user-specific commands to perform tasks such as controller creation, dependency addition, and file configuration.
The devpack for Spring is a classic confinement snap that packages Spring CLI and brings it to Ubuntu. In addition to the upstream functionality, devpack for Spring offers the following features:
- Offline installation of Spring project libraries: these pre-installed Spring libraries reduce the initial build time, provide a consistent set of dependencies and simplify setting up offline builds.
- Pre-configured plugins for Maven and Gradle projects: this provides a consistent set of defaults across the organisation for source code formatting, static analysis and other best practices and policies. This functionality also reduces the boilerplate in the projects, and allows central upgrades of defaults without updating every project.
A special use case we’d like to highlight is that you can export build and runtime images for your projects. Whilst the current version of this devpack only supports exporting build and runtime Ubuntu rocks, we will also look into integrating JIB and Spring Boot Cloud Native Buildpack plugins to generate runtime container images for Spring applications.
Let’s walk through the features of the devpack for Spring, focusing on the added features. Or if you prefer, there is a video walkthrough:
Getting started with devpack for Spring
Installation
At each stage of this demo, we’ve provided a timestamped video link, for you to see the features in action. However, you can still follow the demo without the videos, if you wish. Let’s dive in.
Devpack for Spring is a snap with classic confinement and can be installed with
snap install devpack-for-spring --classic --edge
We will bootstrap a new project for the demo:
devpack-for-spring boot start
This command uses Spring Initializr to generate a new Spring Boot project. We will use Gradle, Java 21 default and Spring Boot 3.4.4
Installed and available offline libraries
Devpack for Spring provides prebuilt binaries of Spring Project libraries as snaps. They are configured to be used with Gradle and Maven builds.
This command lists installed and available offline libraries.:
devpack-for-spring snap list
The Spring Boot project that was created uses Spring Boot 3.4.4, which depends on Spring Framework 6.2.5.
This command installs available libraries:
devpack-for-spring snap install
The command removes the installed libraries:
devpack-for-spring snap remove
Building the project
Let’s build the project and make some changes to the source code:
We will add the dependency on spring-boot-starter-web
and implement a REST controller.
With devpack for Spring, we can run pre-configured build plugins without making the build changes for Gradle projects. The list is limited to io.spring.javaformat
and io.github.rockcrafters.rockcraft
plugins in the current version.
The io.spring.javaformat
plugin formats the project source code according to the Spring coding standards.
The io.github.rockcrafters.rockcraft
plugin provides the ability to create OCI images for building and running the Spring application using Ubuntu Rocks.
Running
devpack-for-spring list-plugins
lists the plugins configured in devpack-for-spring
:
Run
devpack-for-spring plugin format
to format the source code of the project:
Creating a build container
The Rockcraft plugin allows you to create a build container for the project – an OCI image that contains the build toolchain and project dependencies. The plugin needs the rockcraft snap installed:
snap install rockcraft --classic
devpack-for-spring
includes Rockcraft plugin functionality to store dependencies offline:
devpack-for-spring plugin dependencies
The output is stored in target/build-rock/dependencies/
for Maven and build/build-rock/dependencies
for Gradle:
The Rockcraft plugin generates a chiseled build image – an OCI image that includes a headless JDK, the build system (Gradle or Maven), and project dependencies.
The image can be uploaded to the local Docker daemon with:
devpack-for-spring plugin rockcraft push-build-rock
The image name is build-<your-project-name>
:
The build image is a chiselled Ubuntu by default with slices for openjdk, busybox, and git.
It provides a minimal set of dependencies to build the project:
docker run -v `pwd`:`pwd` --user $(id -u):$(id -g) --env PEBBLE=/tmp :latest exec build `pwd` --no-daemon
Visual Studio code provides an extension to develop inside dev containers – images that contain all the tools necessary to develop the application. The extension adds a Visual Studio code server to the image and runs it.
To run Visual Code server we will need to use Ubuntu base for your rock. The Rockcraft plugin allows you to do it by adding a build-rock/rockcraft.yaml
file that contains the overrides for the default build container:
name: build-demo-dev
base: [email protected]
environment:
JAVA_HOME: /usr/lib/jvm/java-21-openjdk-${CRAFT_ARCH_BUILD_FOR}
parts:
dependencies:
plugin: nil
stage-packages:
- openjdk-21-jdk
override-build: craftctl default
To use buildRockcraft
extension in the build.gradle
we will also need to add the plugin:
plugins { id("io.github.rockcrafters.rockcraft") version "1.1.0" ... }
buildRockcraft { rockcraftYaml = "build-rock/rockcraft.yaml" }
A future version of devpack-for-spring
will allow you to do it with a single command.
To use the build rock as a devcontainer in VS Code, add the following .devcontainer.json
to your project:
{
"image" : "<your-build-rock-image>:latest",
"containerUser": "ubuntu"
}
devpack-for-spring
can deploy your application in the chiselled ROCK container.
To build the chiselled runtime image of the Spring Boot application run:
devpack-for-spring plugin rockcraft build-rock
To push the image to the local docker daemon, execute:
devpack-for-spring plugin rockcraft push-rock
The image is tagged
<your-project-name>:latest,<your-project-name>:<your-project-version>
.
See video of building and running the demo application in a chiseled container:
Future developments
The functionality above is just the beginning. We’re excited to bring the benefits of Spring to developers on Ubuntu, and we hope that this new feature empowers our users to kickstart some exciting new projects.
Our next step will be to expand plugin capabilities. We’ll provide refactorings to enable and configure build plugins using openrewrite, and select and pre-configure a set of plugins to improve the quality of life. This means that devpack for Spring will provide an opinionated choice for formatting, code analysis, dependency checking, and reproducible builds. The configuration will also be able to accept pre-configured file snippets to define additional configuration such as checkstyle checks and Rockcraft image overrides files. Ultimately, the goal of this preconfiguration is to make the Spring environment on Ubuntu enjoyable and easy to use.
Another major area we are exploring is the development environment setup and validation. With devpack for spring we intend to offer a choice of setting up JDK, build system, IDE, and the container environment.
As an organization dedicated to open source values, we rely on our community to help us improve and develop our projects. We’d like to invite all of our readers to try out the devpack for Spring and to provide feedback by adding a new issue at https://github.com/canonical/devpack-for-spring/issues.