With a following custom banner.txt file in src/main/resources:
Custom Banner
${application.title}: ${application.version}
When application is built to a native image, printed banner has placeholders resolved to empty strings:
Custom Banner
:
Where the expected output is:
Custom Banner
spring-native-banner-test: 0.0.1-SNAPSHOT
Comment From: mhalbritter
I can't reproduce this:
Custom Banner
the title: 1.0.0-SNAPSHOT
2022-12-08T10:16:53.797+01:00 INFO 131805 --- [ main] com.example.gh33489.Gh33489Application : Starting AOT-processed Gh33489Application using Java 17.0.5 with PID 131805 (/home/moe/Downloads/issue-projects/gh-33489/build/native/nativeCompile/gh-33489 started by moe in /home/moe/Downloads/issue-projects/gh-33489)
2022-12-08T10:16:53.797+01:00 INFO 131805 --- [ main] com.example.gh33489.Gh33489Application : No active profile set, falling back to 1 default profile: "default"
2022-12-08T10:16:53.802+01:00 INFO 131805 --- [ main] com.example.gh33489.Gh33489Application : Started Gh33489Application in 0.016 seconds (process running for 0.025)
with application.properties containing:
application.title=the title
application.version=1.0.0-SNAPSHOT
Do you have a small sample application with which i can reproduce the problem?
Comment From: maciejwalkowiak
With a regular executable JAR build there is no need to set these variables in application.properties. They are taken from somewhere else (perhaps manifest file?)
Comment From: mhalbritter
Ah yes, you are right. They are read from the MANIFEST.MF, which doesn't work in native image.
Comment From: mhalbritter
Hm, unfortunately it isn't as easy as first thought. The entries which are used in the banner are written by the bootJar task:
tasks.named("bootJar") {
manifest {
attributes(
'Implementation-Title': 'myapp',
'Implementation-Version': '1.0.0-SNAPSHOT'
)
}
}
When compiling the native image, we don't use the JAR, we provide the classpath to native-image. Therefore there is no Manifest which contains these entries which we could just register resource hints for.
Even at AOT processing time, the banner looks wrong:
> Task :processAot
Custom Banner, running Spring Boot 3.0.1
:
2023-01-10T14:19:40.236+01:00 INFO 55412 --- [ main] com.example.gh33489.Gh33489Application : Starting Gh33489Application using Java 17.0.5 with PID 55412 (/home/moe/Downloads/issue-projects/gh-33489/build/classes/java/main started by moe in /home/moe/Downloads/issue-projects/gh-33489)
2023-01-10T14:19:40.239+01:00 INFO 55412 --- [ main] com.example.gh33489.Gh33489Application : No active profile set, falling back to 1 default profile: "default"
because the manifest is not yet written.
Comment From: wilkinsona
I suspect the same problem exists with bootRun as well. In other words, this may not be AOT-specific and may also be a problem in 2.x.
Comment From: mhalbritter
Yes, you're right Andy. gradle bootRun prints
Custom Banner, running Spring Boot 3.0.1
:
Comment From: wilkinsona
The docs already have a note about this for application.version. I think the best we can do is to expand that note to cover application.title as well.