Skip to main content

Developer Resources

Deploy Spring Java Backend APIs

Build Deploy with Docker

Pre-Requisites

  • Install and setup
    • Docker Desktop
    • Configure to use Kubernetes via Settings : Kubernetes : Enable Kubernetes

Note: On Windows Run CMD as Administrator. Also for docker compose to work properly, use linux engine, e.g. via below command.

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
  • Tip: On Win: With Docker: High Memory Used by VmmemWSL and Freeing Up Memory

The VmmemWSL is a process running on the background of your computer which support virtual machine usage on your computer.

  • Shutdown via CMD - Administrator Mode wsl --shutdown

Build and Run One Project

  • Locate your project
    • <PROJECTDIR> is referenced as project folder, locate dir backend\spring-java\emapi
cd <PROJECTDIR>
dbrest REST APIs
cd app\dbrest
type Dockerfile | docker build -t dbrest .

List the available docker images:

docker image ls -a

Start container and run image:

docker run -it -p9080:9080 dbrest
dbgraphql GraphQL APIs
cd app\dbgraphql
type Dockerfile | docker build -t dbgraphql .

List the available docker images:

docker image ls -a

Start container and run image:

docker run -it -p9070:9070 dbgraphql

Build and Run Both Project: dbrest & dbgraphql

  • Check/verify build-file
cd <PROJECTDIR>
docker-compose config
  • Build images, create the containers, and start them:
docker-compose up --build
  • Stop the containers
docker-compose down

Code Analysis - Code Coverage, Code Quality

Do static source code analysis, find code coverage and ensure code quality with SonarQube.

Now available with Project Settings Configuration Selection via Builder Studio.

  • Previously available with EasyManage Templates : Backend Templates : Code Coverage Analysis. Pease find it here Backend Templates

SonarQube - Features

  • SonarQube a code quality and security solution that integrates into your CI/CD, and enables you to deploy clean code.
  • Static Code Analysis | SAST
    • Sonar's SAST (static application security testing) engine detects security vulnerabilities in your code. So they can be eliminated before hand.

Generating Code Coverage Locally with JaCoCo, Sonar Scanner

Note: In root level pom.xml Set properties.

  • Edit emapi\pom.xml verify/set below properties to false
  • <sonar.skip> , <jacoco.skip>, <skipITs>, <skipUTs>
  • Run maven goal
mvn clean verify

Local Code Coverage Reports are generated.

  • A separate coverage report will be generated for each module.
  • Also Aggregate Report of all the module-specific reports into one project-level report is generated at:
    • emapi\coverage\target\site\jacoco-aggregate\index.html

Code Analysis with SonarQube

How to run SonarQube Locally From Docker

Note: Use SonarQube Ver 8.9 for JDK 8 compatibility

docker pull sonarqube:8.9-community
docker run -d --name sonarqube -p 9000:9000 sonarqube:8.9-community

View SonarQube Landing Page and later on Reports

  • Go to: http://localhost:9000/

  • First time: Login passowrd change will be required

  • Use new password in place of admin below for mvn sonar:sonar command

How to Analyze Source Code with SonarQube via mvn goal

  • Run maven goal
mvn clean verify sonar:sonar -Dsonar.login=admin -Dsonar.password=admin

After completing, view the results will be available on the SonarQube Projects dashboard

  • http://localhost:9000

Build, Deploy Misc Help & Tips

  • View Maven Dependency

  • View Junit version and other dependencies for spring-boot-starter-test: In IntelliJ you can do this by Ctrl + click onto pom.xml artifactId : spring-boot-starter-test

  • View Maven Dependency via Run Maven Goals

CAUTION: Re-download of dependencies may take place, while using below commands.

  • Show the project dependencies mvn dependency:tree

  • Show plugin dependency tree for each plugin mvn dependency:resolve-plugins