Developing a Maven application using Devpack for Spring

Introduced in the previous post, the devpack-for-spring snap supports developing Gradle and Maven based Spring Boot applications. Though the initial steps here match the Gradle application exercise, the invocation of the rockcraft plugin differs substantially.
Below, I list the steps to create a starter Web application using Maven. If you read the previous post, some of these steps would appear as repetitions; I list them nevertheless to make this post self-sufficient and complete.
Step 1: Install devpack-for-spring
First, let us install thedevpack-for-spring snap, which is a classic confinement snap.
sudo snap install devpack-for-spring --classic
Step 2: Run the setup command
The devpack-for-spring snap offers a setup command, that takes you through a menu and lets you install tools to aid Java application development.
devpack-for-spring setup
At each step, use the arrow keys to move through the list of options. To select an option, use the space bar. Press the enter key to move to the next menu.

The setup command lets you select tools to be auto-installed and auto-configured. For now, it includes:
The OpenJDK / GraalVM CE packages
The container environment - docker, podman etc.
Integrated Development Environment - intellij, vscode etc.
Additional tools - git, rockcraft etc.

Step 3: Install Spring Boot libraries
This is an optional step. The devpack-for-spring snap offers Spring and Spring Boot libraries as content snaps.

To speed up compilation, you may install the libraries you are developing with. For example, I plan to use Spring Boot 3.5.6 for the starter application.
sudo devpack-for-spring snap install content-for-spring-boot-35
The relevant libraries are downloaded under /snap/content-for-spring-boot-35/current/maven-repo/ which is referenced in /root/.m2/settings.xml.
With the Spring Boot dependencies downloaded in the local maven repository, subsequent build times are significantly reduced.
Step 4: Create a starter web application with Maven
The boot start command lets you bootstrap a starter Maven web application. Make sure you select the Maven option, and don’t miss adding the Spring Web dependency.

Step 5: Modify the application to include your code
You may now open the project in the installed Integrated Development Environment and add your code logic to it.
Step 6: Running the format plugin
Optionally, you may run the format plugin to appropriately format/indent your source code. The list-plugins command lists plugins like format, dependencies and rockcraft.
devpack-for-spring list-plugins
To run the format plugin, simply run this:
devpack-for-spring plugin format
Step 7: Run the Rockcraft plugins
The user experience differs quite a lot here. Unlike the Gradle application, invoking the rockcraft plugin with push-rock does not just work out-of-the-box. I had to first add the plugin dependency to the pom.xml
<plugin>
<groupId>io.github.rockcrafters</groupId>
<artifactId>rockcraft-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<configuration>
<createService>false</createService>
</configuration>
<goals>
<goal>create-rock</goal>
<goal>build-rock</goal>
<goal>push-rock</goal>
</goals>
</execution>
</executions>
</plugin>
Even after doing this, the command devpack-for-spring plugin rockcraft rockcraft:push-rock is not expected to do the needful. The only way I could get this building and pushing a container image was by issuing the following:
devpack-for-spring plugin rockcraft install
I raised an issue seeking help.
If this command succeeds, you must find a container image pushed to the local docker daemon.
docker image ls
Step 8: Running the application container
Just like what we’ve been doing in the previous series, run the application using this command:
docker run --network=host demo:latest exec /usr/bin/java -jar /jars/demo-0.0.1-SNAPSHOT.jar
The application should be reachable at localhost:8080.
Here is a screen-cast for the above steps. It includes a demonstration of the format plugin too. In my opinion, Gradle is more user-friendly than Maven. The behavior difference that we see here is a manifestation of this fact!
In my next post, I desire to demonstrate the creation and use of devcontainers. However, my attempts until now have run into various issues. I hope to be back soon! Thanks for reading.




