Coder Social home page Coder Social logo

boot-graalvm's Introduction

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

boot-graalvm's People

Contributors

pottepalemg avatar gpottepalem avatar snyk-bot avatar

Stargazers

 avatar Wesley Oliveira Santos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.