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

为君一笑 提交于 2019-12-05 03:03:46

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

I have exactly the same need, and I don't want to use "delegate IDE build/run action to Gradle" for different (good) reasons.

In my case I don't need that file /META-INF/build-info.properties to be up-to-date in IDEA during develop phase, I just need this file to be available in the "run" classpath (under /out/...), else Spring won't be able to create and inject the BuildProperties bean when launching my app from IDEA run/debug tool.

So here is a simple solution if your are also in my case:

1) create a dummy "dev" (or "snapshot") version of the build-info.properties in the main resources directory ( src/main/resources/META-INF/build-info.properties )

# DO NOT EDIT (will be overriden by Spring boot plugin )
build.time=2019-05-07T11\:32\:31.581Z
build.artifact=myapp
build.group=org.mycompany
build.name=myapp
build.version=dev

This dev version will be automatically copied into IDEA /out/production/resources directory when building project from IDEA

2) Create a task dependency between bootBuildInfo task and processResources tasks, to make sure that Spring boot plugin will override the "dev" version with up-to-date version when building the app jar:

bootBuildInfo.mustRunAfter processResources

This way, SpringBoot gradle plugin will override the file copied from sources by processResources task, with its auto-generated up-to-date file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!