Open yeekangc opened 3 years ago
It might help to include some workarounds in the meantime...
Some options here are:
1) Use a plain WAR package (use SpringBoot just as a set of APIs but not its JAR packaging).
In this case you can use plain dev mode. Downside is the WAR is large and doesn't get to leverage layering in Docker very well.
2) Use the guide approach: https://github.com/openliberty/guide-spring-boot
This approach builds upon well known commands, but it's kind of slow for iterative development.
By binding the liberty:package goal to the package phase we enable you do do mvn package; java -jar .../my.jar
for local dev. But that's a fairly slow cycle. It also even might slow down the Docker build some, considering you probably want to do mvn package
first but now you're unnecessarily building the Liberty runnable jar with this command.
3) Use the SpringBoot JAR package with some custom Liberty commands/config.
This approach is nice in that it is a decently-quick iterative cycle. It requires a small change on top of what you'd generate say from the Spring Initializr, but the downside is that you have to do the magic commands.
You could simply configure this in your pom.xml:
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.10</version>
<configuration>
<deployPackages>spring-boot-project</deployPackages>
</configuration>
</plugin>
and either copy a server.xml activating SpringBoot or use a template (you could do it during the execution invocation even e.g. using -Dtemplate=springBoot3
).
You can start Liberty then with simply:
mvn clean package liberty:run
Once the app is up and running, you can make source changes and rebuild/deploy in a single step by doing this in a separate terminal:
mvn package liberty:deploy
There are variants of this.. you could avoid even touching the pom.xml using
mvn package io.openliberty.tools:liberty-maven-plugin:3.10:run -DdeployPackages=spring-boot-project
with:
mvn package io.openliberty.tools:liberty-maven-plugin:3.10:deploy -DdeployPackages=spring-boot-project
on each change. That's more to remember obviously.
You could obviously do: mvn package liberty:deploy -DskipTests
for a quicker update.
But you are still doing a minimal liberty-maven-plugin config and getting a quick iterative cycle, once you know the magic commands.
Some design thoughts on implementing dev mode for SpringBoot:
Can we use a "loose" app with application classes simply in a directory rather than zipped up into the application JAR? Or do we actually need to go through the SB repackage for each app update (obviously it'd seem the update would be quicker if we don't)?
Should we consider enhancing our all-in-one goals: run/dev so that a user can do: mvn liberty:run
or mvn liberty:dev
without having to run mvn package liberty:run
? E.g. should liberty:run do all these SB related goals: spring-boot:test jar:jar spring-boot:repackage
? Likewise should the dev mode loop do each upon update? (Yes, this is in some ways just an extension of question 1.).
Is there anything we can do to autodetect the SpringBoot JAR package type so that the user doesn't have to do: -DdeployPackages=spring-boot-project
? After all, you can't deploy a Jakarta-type JAR currently.
Enhancement to consider general support in dev mode for Spring Boot apps.
Atm, specific setup is required for working with Spring Boot apps in dev mode. See https://github.com/OpenLiberty/ci.maven/issues/1143
Cc @ericglau