Application version does not show up in Spring Boot banner.txt

Another solution:

Use the maven resources plugin to "filter" (replace) properties in resource files.

In the pom, activate resources filtering with the following definition:

<resources>
    <resource>
        <filtering>true</filtering>
        <directory>src/main/resources</directory>
        <includes>
            <include>application.properties</include>
        </includes>
    </resource>
</resources>

In the application.properties file:

[email protected]@
[email protected]@

In the banner.txt file:

${info.app.name} (${info.app.version})

Ok, the version gets printed if i build the project and run it via java -jar. But if i start the application within my IDE (IntelliJ IDEA) the version will not be printed.

According to the Spring Boot documentation on Customizing the Banner, the value of ${application.version} is taken from the jar manifest.

The version number of your application as declared in MANIFEST.MF. For example Implementation-Version: 1.0 is printed as 1.0.

When running from an IDE, it's typical for execution to occur against the class files compiled by the IDE. The IDE typically doesn't go through a full cycle of building the whole jar with a manifest. Therefore, there is no MANIFEST.MF available at runtime for substituting the value of ${application.version}, and you're left with the bare token.

This is not a bug in your code, and you've already seen that it works correctly when doing a full jar build. If it's really important to fix this while running through the IDE, then you could consider setting up a custom build step that does go through the full jar build and manifest generation first. That's probably overkill though. The banner could be validated later outside the IDE by testing against a real release build of the jar.


Just for reference, here's what I found works for the command-line in Spring Boot 2 with a Gradle-based project (using the Spring Boot Gradle plugin). Intellij’s console still doesn't work for me, but that problem has been around for several years now.

Using the jar task wasn't working for me on a standard 2.0.5.RELEASE build.gradle, because the bootJar task takes precedence:

By default, when the bootJar or bootWar tasks are configured, the jar or war tasks are disabled.

So I tried the bootJar task, and it works:

version = '0.0.1-SNAPSHOT'

bootJar {
    mainClassName = 'com.demo.Application'
    manifest {
        attributes('Implementation-Title':   'Demo Application',
                   'Implementation-Version': version)
    }
}

Note: There is no need for mainClassName and its equivalents if you have only one main class. The discovered or configured main class is automatically added to the MANIFEST.MF as 'Start-Class'.

Once this is working, you can use ${application.title} and ${application.version} as usual in your Spring Boot banner.txt file.