How to use S2I for springboot application + gradle

Latest response

I am trying to build and deploy a simple spring boot appusing openshift S2I. It uses gradle. Below is the link to repo. https://github.com/am7ey/student-spring-boot. Error details are as follows . Can someone share the guide lines for deploying springboot application using S2I.

I am getting following erroe when .class or .jar file is not checked in.

Starting the Java application using /opt/run-java/run-java.sh ...
ERROR: Neither $JAVA_MAIN_CLASS nor $JAVA_APP_JAR is set and 0 JARs found in /deployments (1 expected)
exec java -javaagent:/opt/jolokia/jolokia.jar=config=/opt/jolokia/etc/jolokia.properties -Xms256m -Xmx256m -XX:+UseParallelGC -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m -XX:ParallelGCThreads=1 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -XX:CICompilerCount=2 -XX:+ExitOnOutOfMemoryError -cp . -jar

After adding .jar file following error.

Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
INFO exec java -javaagent:/opt/jboss/container/jolokia/jolokia.jar=config=/opt/jboss/container/jolokia/etc/jolokia.properties -XX:+UseParallelOldGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m -XX:+ExitOnOutOfMemoryError -cp ".:/deployments/*" StudentApplication.class
E

Responses

I have a similar situation, the following ones:

1- Dockerfile: https://github.com/jlozano-rh/gradle-hello/blob/main/Dockerfile

2- Fabric8/s2i: https://developers.redhat.com/blog/2018/12/18/openshift-java-s2i-builder-java-11-grade

But the 2nd options is from 3rd party and uses an obsolete docker image, but is the most closely to original openshift s2i java image (same experience).

I need to know too, what is the correct way to deploy a java + gradle application in an OpenShift cluster. Regards!

Hi

Not sure this will work for your gradle problem, but are you setting the "ARTIFACT_DIR" environment in your s2i build environments? This ENVAR should point to the folder containing the articfacts of your java build and these will then be copied to the /deployment folder. This fixed the exact same error for me in our java apps.

Some documentation: https://docs.okd.io/3.9/using_images/s2i_images/java.html https://docs.openshift.com/online/pro/using_images/s2i_images/java.html#s2i-images-java-deploy-applications-from-binary https://github.com/fabric8io-images/s2i/blob/master/java/templates/s2i/assemble