Skip to content

gpottepalem/boot-graalvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boot GraalVM

Build Status Known Vulnerabilities

This is simple Spring Boot REST application which can be built to native Java, nothing but a native executable produced using Spring ahead-of-time (AOT) compilation.

A native image can run standalone without relying on a JVM.

The following are the dependencies chosen from

Project      : Maven 3.9.6 
Languge      : Java 21  
Spring Boot  : 3.2.1
Packaging    : Jar
Dependencies : Lombok, GraalVM Native Support, Spring Web, Testcontainers, Docker Compose, JPA

Getting Started

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

Additional Links

These additional references should also help you:

Build

GraalVM

NOTE: GraalVM 22.3+ is required.

Make sure that your JAVA_HOME points to GraalVM JDK distribution.

e.g. Using SDKMAN

$ sdk install java 21-graal 
$ sdk use java 21-graal
$ java -version 
java version "21" 2023-09-19
Java(TM) SE Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)
$

GraalVM Native Support

This project has been configured to let you generate either a lightweight container or a native executable. It is also possible to run your tests in a native image.

1. Lightweight Container with Cloud Native Buildpacks

If you're already familiar with Spring Boot container images support, this is the easiest way to get started. Docker should be installed and configured on your machine prior to creating the image.

To create the image, run the following goal:

$ ./mvnw spring-boot:build-image -Pnative

Then, you can run the app like any other container:

$ docker run --rm -p 8080:8080 boot-graalvm:0.0.1-SNAPSHOT

2. Building GraalVM Native Image(Executable) with Native Build Tools

Use this option if you want to explore more options such as running your tests in a native image. The GraalVM native-image compiler should be installed and configured on your machine.

To create the executable, run the following goal:

$ ./mvnw native:compile -Pnative

Running

Then, you can run the app as follows for local profile:

$ target/boot-graalvm -Dspring.profiles.active=local

Once the app is running, run the following curl command from another terminal window:

curl get localhost:8080

You can also run your existing tests suite in a native image. This is an efficient way to validate the compatibility of your application.

To run your existing tests in a native image, run the following goal:

$ ./mvnw test -PnativeTest

Unit Tests, and Integration Tests

With added Spock support (spock-core and spock-spring), test cases can be written as JUnit 5 or Spock specifications in both Java and Groovy.

Maven Suerfire and Failsafe plugins are configured to run both Java JUnit 5 Tests and Groovy Spock Specifications.

Tests skip flags

-DskipTests skips all tests
-DskipUnitTests skips all unit tests but not integration tests
-DskipIntegrationTests skips all integration tests, but not unit tests

Example Maven commands

# Run all unit tests
./mvnw test
# Run specific unit test
./mvnw test -Dtest=HelloControllerTest

#TODO Run specific unit tet method

# Run all integration tests, skip unit tests
./mvnw integration-test -DskipUnitTests

# Run specific integration test, skip unit tests
./mvnw integration-test -Dit.test=AccountServiceIT -DskipUnitTests

# Run specific integration test, and unit tests
./mvnw integration-test -Dit.test=HelloControllerIS

#TODO Run specific integration tet method

Code Coverage Reports

Run one of the following and open index.html in browser from <project-home>/target/site/index.html for JaCoCo Code Coverage Reports.:

$ ./mvnw clen install
$ ./mvnw clean test
$ ./mvnw native:compile -Pnative

Swagger UI

Once the app is up and running, just go to http://localhost:8080/swagger-ui/index.html in the browser to test end-points.

Actuator

http://localhost:8080/actuator

About

Spring Boot REST application which can be built to "native Java"

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published