Getting the Gradle.build version into Spring Boot

前端 未结 4 1706
广开言路
广开言路 2021-01-03 23:35

I\'m trying to display the application version of my Spring Boot application in a view. I\'m sure I can access this version information, I just don\'t know how.

I tr

4条回答
  •  孤城傲影
    2021-01-04 00:09

    As described in the reference documentation, you need to instruct Gradle to process you application's resources so that it will replace the ${version} placeholder with the project's version:

    processResources {
        expand(project.properties)
    }
    

    To be safe, you may want to narrow things down so that only application.properties is processed:

    processResources {
        filesMatching('application.properties') {
            expand(project.properties)
        }
    }
    

    Now, assuming that your property is named info.build.version, it'll be available via @Value:

    @Value("${info.build.version}")
    

提交回复
热议问题