Include generated version.properties to resources.
muzuro opened this issue · 3 comments
Thanks for great plugin!
How can we include generated version.properties to resources?
Is there way this file to be included to resources by executing gradle assemble/build task, or when we execute project in IDE(IDEA, eclipse)?
Details:
I am using IDEA with spring boot appliction. I need to show version and git hash at bottom of main html page. To achive this i created controller wich read property file and display "VERSION_DISPLAY" value. So i need generated file be included in resources. I have added this configuration:
versionFile {
// Path to the file to be written
file = new File(project.buildDir, 'resources/main/version.properties')
}
processResources.dependsOn.add("versionFile")
This file is successfully included when i build jar with gradle, but when i launch application from IDEA - this file not included.
Hi,
I do like this, by generating a specific Spring Boot file:
task generateVersionInfo {
doLast {
File file = project.file('src/main/resources/application.properties')
file.text = """\
# This file is generated at build time to contain version information
# For the /manage/info endpoint
info.app.version = ${rootProject.versioning.info.display}
info.build.date = ${new Date().format("yyyy-MM-dd'T'HH:mm:ss")}
info.build.display = ${rootProject.versioning.info.display}
info.build.full = ${rootProject.versioning.info.full}
info.build.branch = ${rootProject.versioning.info.branchId}
info.build.build = ${rootProject.versioning.info.build}
info.build.commit = ${rootProject.versioning.info.commit}
info.build.source = ${rootProject.versioning.info.branch}
info.build.sourceType = ${rootProject.versioning.info.branchType}
"""
}
}
processResources.dependsOn generateVersionInfo
This way:
- I do not depend on the
versionFile
task - the property file feeds directly the info management point of Spring Boot
- can still be accessed from your own code if needed
As for IDEA, I have exactly the same issue. Just make sure your call processResources
before launching you app?
Best regards,
Damien.
Thanks! Yeah, reason was processResources is not launched when IDEA boot dashboard is used, perhaps will use spring-boot gradle task.