How do I generate build-info.properties in the IntelliJ "out" directory on debug/run for a Spring Boot project?

Don Rhummy picture Don Rhummy · Nov 28, 2017 · Viewed 7.1k times · Source

In my build.gradle, I have added spring build info:

springBoot {
    mainClass = "${springBootMainClass}"

    buildInfo() {
        additionalProperties = [
                name: "${appName}",
                version: "${version}-${buildNumber}",
                time: buildTime()
        ]
    }
}

def buildTime() {
    final dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ")
    dateFormat.timeZone = TimeZone.getTimeZone('GMT')
    dateFormat.format(new Date())
}

When I run from the command line, this correctly adds the /META-INF/build-info.properties file into /build/resources/main so that the "/info" endpoint shows the build information in JSON.

When I run from IntelliJ's run/debug button, IntelliJ does not use the /build directory but instead uses the /out directory and also does not run that gradle task, so the /info endpoint has empty JSON.

How can I make it generate that file and put it in the /out directory?

Answer

Andrey picture Andrey · Jan 2, 2018

Enable Delegate IDE build/run actions to Gradle option in Settings (Preferences) | Build, Execution, Deployment | Build Tools | Gradle | Runner tab.

In latest IDE versions set Gradle for the Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Build and run using option.