I tend to use the runnable JAR during development, but I need a WAR for deployment.
I've followed this article about converting from a JAR to WAR Spring Boot Gradle build.
However, right now, everytime I switch the builds from one to the other, I have to comment and uncomment the specific parts of the build file.
Is there a cleaner way of handling allowing for both a JAR and WAR build?
The war that gets build for deployment (that is if you added the spring-boot maven plugin) is just as runnable as a jar file.
java -jar mywar.war
And presto it starts with an embedded server, you can deploy the same war to your server and then it doesn't use an embedded server.
You can specify pom or gradle build file when you build.
So, you can create multiple pom files (one for jar packaging, the other for war packaging) for maven builds, also do same for gradle builds.
For example, if you setup pom.xml or build.gradle file for jar packaging and also setup pomWar.xml or buildWar.gradle for war packaging, then you can run below command
[ build jar packaging by maven ]
$ mvn clean install
[ build jar packaging by gradle ]
$ gradle clean test bootRepackage
[ build war packaging by maven ]
$ mvn -f pomWar.xml clean install
[ build war packaging by gradle ]
$ gradle -b buildWar.gradle clean test bootRepackage
war file can't be dependency of other project. so if you has other project has dependency on your spring boot project, then that is the case where you want to setup two different build files like above on your build machine