I have problem with compilation of my Spring boot application.
TL;DR: Error: Could not find target method: private org.springframework.boot.Banner org.springframework.nativex.substitutions.boot.Target_SpringApplicationBannerPrinter.getImageBanner(org.springframework.core.env.Environment)
I'm using:
- graalvm-ce-java17-linux-amd64-22.3.1
- Spring Boot 3.0.2
- Buildpack gcr.io/paketo-buildpacks/bellsoft-liberica:9.10.3
pom.xml
plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/bellsoft-liberica:9.10.3</buildpack>
<buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
</buildpacks>
</image>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
.gitlab-ci.yml
:
stages:
- build
build:
stage: build
image:
name: maven:3-eclipse-temurin-17-focal
before_script:
- set -e
- apt-get update
- apt-get -y install wget build-essential zlibc zlib1g zlib1g-dev upx-ucl
- wget -q https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java17-linux-amd64-22.3.1.tar.gz
- tar xzf graalvm-ce-java17-linux-amd64-22.3.1.tar.gz
- mkdir -p /usr/lib/jvm
- mv graalvm-ce-java17-22.3.1 /usr/lib/jvm/graalvm
- export PATH=/usr/lib/jvm/graalvm/bin/:$PATH
- export JAVA_HOME=/usr/lib/jvm/graalvm
- gu install native-image
- java --version
- native-image --version
script:
- ./compile.sh
artifacts:
expire_in: 1 days
paths:
- ${CI_PROJECT_DIR}/target/app-0.0.1-SNAPSHOT.jar
- ${CI_PROJECT_DIR}/target/app
and compile.sh
:
#!/bin/bash
set -e
mvn -Pnative spring-boot:build-image
rm -rf target/native
mkdir -p target/native
cd target/native
jar -xvf ../app-0.0.1-SNAPSHOT.jar
touch META-INF/native-image/argfile
native-image -H:Name=app \
@META-INF/native-image/argfile \
-H: ReportExceptionStackTraces \
-H:TraceClassInitialization=true \
-H:IncludeResources=".*" \
--initialize-at-build-time=\
com.fasterxml.jackson.annotation.JsonProperty\
,org.slf4j.impl.StaticLoggerBinder\
,org.slf4j.LoggerFactory\
,org.slf4j.simple.SimpleLogger\
,ch.qos.logback.classic.Logger\
,ch.qos.logback.core.spi.AppenderAttachableImpl\
,ch.qos.logback.core.status.StatusBase\
,ch.qos.logback.classic.Level\
,ch.qos.logback.core.status.InfoStatus\
,ch.qos.logback.classic.PatternLayout\
,ch.qos.logback.core.CoreConstants\
,ch.qos.logback.core.pattern.parser.Parser \
-cp .:BOOT-INF/classes:`find BOOT-INF/lib | tr '\n' ':'`
mv app ../
The application works fine when running from JAR. But compilation crashes on:
Error: Could not find target method: private org.springframework.boot.Banner org.springframework.nativex.substitutions.boot.Target_SpringApplicationBannerPrinter.getImageBanner(org.springframework.core.env.Environment)
Full output:
[INFO] [creator] Paketo Buildpack for Native Image 5.8.0
[INFO] [creator] https://github.com/paketo-buildpacks/native-image
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_BINARY_COMPRESSION_METHOD Compression mechanism used to reduce binary size. Options: `none` (default), `upx` or `gzexe`
[INFO] [creator] $BP_NATIVE_IMAGE true enable native image build
[INFO] [creator] $BP_NATIVE_IMAGE_BUILD_ARGUMENTS arguments to pass to the native-image command
[INFO] [creator] $BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE a file with arguments to pass to the native-image command
[INFO] [creator] $BP_NATIVE_IMAGE_BUILT_ARTIFACT the built application artifact explicitly, required if building from a JAR
[INFO] [creator] Native Image: Contributing to layer
[INFO] [creator] Executing native-image -H: StaticExecutableWithDynamicLibC -H:Name=/layers/paketo-buildpacks_native-image/native-image/cloud.mwapp.app.appApplication -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/logback-classic-1.4.5.jar:/workspace/BOOT-INF/lib/logback-core-1.4.5.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.19.0.jar:/workspace/BOOT-INF/lib/log4j-api-2.19.0.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-2.0.6.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar:/workspace/BOOT-INF/lib/snakeyaml-1.33.jar:/workspace/BOOT-INF/lib/jackson-databind-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-core-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.14.1.jar:/workspace/BOOT-INF/lib/tomcat-embed-core-10.1.5.jar:/workspace/BOOT-INF/lib/tomcat-embed-el-10.1.5.jar:/workspace/BOOT-INF/lib/tomcat-embed-websocket-10.1.5.jar:/workspace/BOOT-INF/lib/spring-web-6.0.4.jar:/workspace/BOOT-INF/lib/spring-beans-6.0.4.jar:/workspace/BOOT-INF/lib/micrometer-observation-1.10.3.jar:/workspace/BOOT-INF/lib/micrometer-commons-1.10.3.jar:/workspace/BOOT-INF/lib/spring-webmvc-6.0.4.jar:/workspace/BOOT-INF/lib/spring-aop-6.0.4.jar:/workspace/BOOT-INF/lib/spring-context-6.0.4.jar:/workspace/BOOT-INF/lib/spring-expression-6.0.4.jar:/workspace/BOOT-INF/lib/slf4j-api-2.0.6.jar:/workspace/BOOT-INF/lib/jakarta.xml.bind-api-4.0.0.jar:/workspace/BOOT-INF/lib/jakarta.activation-api-2.1.1.jar:/workspace/BOOT-INF/lib/spring-core-6.0.4.jar:/workspace/BOOT-INF/lib/spring-jcl-6.0.4.jar:/workspace/BOOT-INF/lib/spring-boot-3.0.2.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-3.0.2.jar:/workspace/BOOT-INF/lib/springdoc-openapi-starter-webmvc-ui-2.0.2.jar:/workspace/BOOT-INF/lib/springdoc-openapi-starter-webmvc-api-2.0.2.jar:/workspace/BOOT-INF/lib/springdoc-openapi-starter-common-2.0.2.jar:/workspace/BOOT-INF/lib/swagger-core-jakarta-2.2.7.jar:/workspace/BOOT-INF/lib/swagger-annotations-jakarta-2.2.7.jar:/workspace/BOOT-INF/lib/swagger-models-jakarta-2.2.7.jar:/workspace/BOOT-INF/lib/swagger-ui-4.15.5.jar:/workspace/BOOT-INF/lib/webjars-locator-core-0.52.jar:/workspace/BOOT-INF/lib/classgraph-4.8.149.jar:/workspace/BOOT-INF/lib/springdoc-openapi-native-1.6.14.jar:/workspace/BOOT-INF/lib/springdoc-openapi-common-1.6.14.jar:/workspace/BOOT-INF/lib/swagger-core-2.2.7.jar:/workspace/BOOT-INF/lib/commons-lang3-3.12.0.jar:/workspace/BOOT-INF/lib/jackson-dataformat-yaml-2.14.1.jar:/workspace/BOOT-INF/lib/swagger-annotations-2.2.7.jar:/workspace/BOOT-INF/lib/swagger-models-2.2.7.jar:/workspace/BOOT-INF/lib/jakarta.validation-api-3.0.2.jar:/workspace/BOOT-INF/lib/spring-native-0.12.1.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-3.0.2.jar cloud.mwapp.app.appApplication
[INFO] [creator] ================================================================================
[INFO] [creator] GraalVM Native Image: Generating '/layers/paketo-buildpacks_native-image/native-image/cloud.mwapp.app.appApplication' (static executable)...
[INFO] [creator] ================================================================================
[INFO] [creator]
[INFO] [creator] [1/7] Initializing... (0.0s @ 0.27GB)
[INFO] [creator] Error: Could not find target method: private org.springframework.boot.Banner org.springframework.nativex.substitutions.boot.Target_SpringApplicationBannerPrinter.getImageBanner(org.springframework.core.env.Environment)
[INFO] [creator] Error: Use -H: ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO] [creator] --------------------------------------------------------------------------------
[INFO] [creator] 0.8s (5.5% of total time) in 8 GCs | Peak RSS: 0.62GB | CPU load: 1.91
[INFO] [creator] ================================================================================
[INFO] [creator] Failed generating '/layers/paketo-buildpacks_native-image/native-image/cloud.mwapp.app.appApplication' after 12.8s.
[INFO] [creator] Error: Image build request failed with exit status 1
[INFO] [creator] unable to invoke layer creator
[INFO] [creator] unable to contribute native-image layer
[INFO] [creator] error running build
[INFO] [creator] exit status 1
[INFO] [creator] ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:23 min
[INFO] Finished at: 2023-01-30T12:40:18Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:build-image (default-cli) on project app: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:build-image failed: Builder lifecycle 'creator' failed with status code 51 -> [Help 1]
I'm stuck on this and can't figure it out. Can someone please advise me?
CodePudding user response:
The org.springframework.nativex.substitutions.boot.Target_SpringApplicationBannerPrinter
class comes from the Spring Native experimental project. Spring Native is only compatible with Spring Boot 2.7, and should not be used with Spring Boot 3.0. Spring Framework 6.0 and Spring Boot 3.0 have GraalVM native executable capabilities built in.
Remove the Spring Native dependencies from your application and follow the Spring Boot 3 documentation.