【发布时间】:2018-06-16 10:04:33
【问题描述】:
我正在使用 Gradle 和 Spring Boot 2.0.0.M7 并应用了以下插件:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7"
}
}
plugins {
id "com.gorylenko.gradle-git-properties" version "1.4.17"
}
spring-boot-starter-actuator 依赖也存在。 git.properties 文件正确生成到build/main/resoures 目录。我还添加了属性management.info.git.mode=full。由于官方文档,git information should be added 到/info 端点自动与GitInfoContributor。然而,以上都没有帮助,/info 端点返回空 JSON - {}。关于如何解决此问题的任何想法?
更新 1:
到目前为止,我发现如果我手动将git.properties 复制到out/resources,这样它就可以工作,但由于某种原因它们没有放在那里。
更新 2:
当我使用 gradle bootRun 运行时,它可以工作,但是当我从 Intellij IDEA 启动它时,我们运行 gradle clean build 运行测试,检查这些属性是否显示在 /info 端点上 - 它不起作用。
【问题讨论】:
-
似乎您也需要应用插件(否则 git.properties 文件未捆绑在 jar 中):
apply plugin: "com.gorylenko.gradle-git-properties" -
不幸的是,这没有帮助。据我所知,使用 Gradle > 2.1,如果您指定
plugins部分,则可以跳过应用部分。 plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties -
获取与jar打包的
git.properties文件? -
是的,我看到它打包在 jar 中的
BOOT-INF/classesdir 中。我刚刚发现的一个有趣的事实是,使用gradle bootRun它可以工作,但是当我从 Intellij IDEA 启动它时,我们运行gradle clean build运行检查这些属性是否显示在 /info 上的测试 - 它不起作用. -
所以我认为它被打包然后就可以工作了。但是在打包之前,比如从 IDE 运行或从测试运行 - 它没有。
标签: spring spring-boot gradle spring-boot-actuator spring-boot-gradle-plugin