Use java S2I for spring boot app with gradle build in openshift - spring-boot

How to get started with java S2I build for spring boot application with Gradle build?
Please suggest me any Json/yml file needs to be imported to get started.

Here is a whole repo - https://github.com/dsevost/gradle-s2i - with a Dockerfile to build a S2I gradle builder image, and a template to build applications on top of it.
Perhaps it is worth noting the BUILDER parameter in the template with possible values of 'Gradle' or 'Maven'. According to the assemble script, it will build a gradle project even when both pom.xml and build.gradle are present in the project directory.
I haven't tried it myself but I glanced over the template and it looks OK...assuming the image and S2I scripts are functional.

Related

Hot reloading a multi-module spring boot application with gradle

I'm trying to convert a project from maven to gradle, but I'm having trouble getting hot reloading to work the same way. I can't show the actual project so I've created two identical very simple projects. One with maven one with gradle. These projects contain two modules:
project
|____api
|____lib
The /api module contains a spring-boot app which depends on code from the /lib module
In the maven project I can change code in either of these modules and recompile either with my IDE (intellij) or with the maven cli and spring-boot-devtools will hot reload the application. However in the gradle version it only successfully hot reloads code that has changed in the /api module.
From what I gathered this seems like a classpath issue. If you run gradle or maven in debug mode it prints out the classpath it passes when it starts the application. Maven includes <project_dir>/lib/target/classes/kotlin/main. However gradle only includes <project_dir>/lib/build/libs/lib.jar
I'm very new to gradle to I might have some of the build configuration messed up. Here are the two project repo's:
Maven: https://github.com/Perry-Olsson/mvn-hot-reload
Gradle: https://github.com/Perry-Olsson/gradle-hot-reload

How to execute only image build with spring boot maven plugin

I'm using Spring Boot 2.5.x and I create the docker image with the following command
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=myImage
The goal "build-image" seems execute the "verify" also.
Is it possible to execute only the build image without redoing the build of the project?
Is it possible to execute only the build image without redoing the build of the project?
Not currently, because spring-boot:build-image forks the Maven lifecycle to run the package phase. The design is discussed in a Spring Boot issue. There isn't a good solution yet to meeting the needs of both uses cases (the current use case of running spring-boot:build-image without requiring a jar to be built first, and the use case of not re-building when the jar is already built).

How to add a runtime library on Gradle in the build command

I have a build.gradle file that I want to use to build a Spring Boot microservice for multiple projects. I have created a custom library with some classes that should not be in all of the projects but I don't want to have to edit the build.gradle file when I build the microservice depending on which project I will use it in.
How can I add a command/parameter to gradle build that can add runtime libraries to the Spring Boot app?
Something like (just an exaple):
gradle buildDocker -PaddRuntime=com.skios.lib:lib-common:0.2.35
Thanks for any directions
I am not sure I understand your issue fully and thus not convinced this is the best solution.
But since a Gradle build script accepts code, you can have conditionals in a dependencies block:
dependencies {
if (project.hasProperty('addRuntime')) {
runtimeOnly('com.skios.lib:lib-common:0.2.35')
}
}
and then on the command line: ./gradlew buildDocker -PaddRuntime

How to run codes written with maven build in Gradle

if I have created a spring Boot application using maven. Now I have to run the same codes in Gradle,So what all changes I have to make.
Here is the migration guide maven to gradle
A simple project can migrated by following chapter 3
3. Run an automatic conversion
install gradle to you system
run gradle init
Accordig to the same guide:
You’ll find that the new Gradle build includes the following:
All the custom repositories that are specified in the POM
Your external and inter-project dependencies
The appropriate plugins to build the project (limited to one or more of the Maven Publish, Java and War Plugins)

Use of spring-boot-maven-plugin

While creating a spring boot project I define property in pom.xml as <packaging>war</packaging> with which I can create a war and thereafter deploy the war into server maybe tomcat or WAS.
But I came across a plugin named spring-boot-maven-plugin whose documentation states that it's use is to package executable jar or war archives and run an application in-place.
My query is why do we need this at all ?
If my packaging can tell me what to create and then can deploy it to run, what is the used of this plugin.
I am trying to understand a new project so wanted to be sure that every line makes sense
The maven plugin will create an "executable" archive. In the case of the war packaging, you would be able to execute your app with java -jar my-app.war. If you intend to deploy your Spring Boot application in an existing Servlet container, then this plugin is, indeed, not necessary.
The maven plugin does more things like running your app from the shell or creating build information.
Check the documentation
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven, letting you package executable jar or war archives and run an application “in-place”.
Refer this - https://www.javaguides.net/2019/02/use-of-spring-boot-maven-plugin-with.html

Resources