Building

This section covers how to build a Spring Shell application.

Starters

Table 1. Spring Shell Starters
Name Description

spring-shell-starter

Basic Spring Shell modules

spring-shell-starter-jansi

With JLine jansi provider

spring-shell-starter-jni

With JLine jni provider

spring-shell-starter-jna

With JLine jna provider

spring-shell-starter-ffm

With JLine ffm provider (requires JDK22+)

spring-shell-starter-test

Spring Shell testing support

All Spring Shell starters import spring-boot-starter, so there is no need to import spring-boot-starter when using a Spring Shell starter.

Terminal Providers

JLine uses terminal providers to interact with the underlying terminal through native libraries. The jansi, jni, and jna providers offer different native integrations. JLine detects the available providers and selects one.

Use the corresponding Spring Shell starter to add a particular provider.

FFM

The Foreign Function and Memory (FFM) API was finalized in JDK 22. The spring-shell-starter-ffm starter adds JLine’s FFM terminal provider, which requires JDK 22 or later at runtime.

Enable native access when using the FFM provider:

--enable-native-access=ALL-UNNAMED

For an executable JAR, you can put this setting in META-INF/MANIFEST.MF.

Enable-Native-Access: ALL-UNNAMED

For example, add this manifest entry with Gradle:

tasks.named("bootJar") {
    manifest {
        attributes 'Enable-Native-Access': 'ALL-UNNAMED'
    }
}
JLine checks that native access is enabled before using the FFM provider.

Native Support

Support for compiling a Spring Shell application into a GraalVM binary mostly comes from Spring Framework and Spring Boot where the feature is called AOT. Ahead of Time means that the application context is prepared at build time for GraalVM native image generation.

Spring Shell provides additional GraalVM reachability hints on top of Spring’s AOT support. Third-party libraries may need further metadata if they do not provide complete native image configuration.

It is required to use GraalVM Reachability Metadata Repository which provides some missing hints for 3rd party libraries. Also you need to have GraalVM installed and JAVA_HOME pointing to that.

For Gradle, add GraalVM’s native build tools plugin and configure the metadata repository. Replace <native-build-tools-version> with a native build tools plugin version compatible with your Spring Boot version.

plugins {
	id 'org.graalvm.buildtools.native' version '<native-build-tools-version>'
}

graalvmNative {
	metadataRepository {
        enabled = true
	}
}

When the Gradle build is run with ./gradlew nativeCompile you should get a binary under build/native/nativeCompile directory.

For Maven, use spring-boot-starter-parent as the parent and you get a native profile which can be used to do a native compilation. You need to configure the metadata repository:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <metadataRepository>
                        <enabled>true</enabled>
                    </metadataRepository>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
If you rely on spring-boot-starter-parent it manages native-maven-plugin version which is kept up to date.

When the Maven build is run with ./mvnw native:compile -Pnative you should get a binary under target directory.

If everything went well this binary can be run as is instead of executing Spring Boot application JAR with the JVM.