如何在IntelliJ"out"窗口中生成build-info.properties. Spring Boot项目的调试/运行目录? [英] How do I generate build-info.properties in the IntelliJ "out" directory on debug/run for a Spring Boot project?

查看:443
本文介绍了如何在IntelliJ"out"窗口中生成build-info.properties. Spring Boot项目的调试/运行目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的build.gradle中,我添加了spring的构建信息:

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())
}

当我从命令行运行时,这会将/META-INF/build-info.properties文件正确地添加到/build/resources/main中,以便"/info"端点以JSON显示构建信息.

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.

当我从IntelliJ的运行/调试按钮运行时,IntelliJ不会使用/build目录,而是使用/out目录,并且也不会运行gradle任务,因此端点具有空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.

如何使它生成该文件并将其放在/out目录中?

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

推荐答案

启用设置(首选项)"中的将IDE生成/运行操作委托给Gradle 选项|构建,执行,部署|生成工具|摇篮| 赛跑者标签.

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

这篇关于如何在IntelliJ"out"窗口中生成build-info.properties. Spring Boot项目的调试/运行目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆