【问题标题】:Spring Boot 2.0 Actuator git properties not added to /infoSpring Boot 2.0 Actuator git 属性未添加到 /info
【发布时间】:2018-06-16 10:04:33
【问题描述】:

我正在使用 GradleSpring 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/classes dir 中。我刚刚发现的一个有趣的事实是,使用gradle bootRun 它可以工作,但是当我从 Intellij IDEA 启动它时,我们运行gradle clean build 运行检查这些属性是否显示在 /info 上的测试 - 它不起作用.
  • 所以我认为它被打包然后就可以工作了。但是在打包之前,比如从 IDE 运行或从测试运行 - 它没有。

标签: spring spring-boot gradle spring-boot-actuator spring-boot-gradle-plugin


【解决方案1】:

问题是从 IDE 运行应用程序。由于这些属性是在组装 JAR 的阶段生成的,因此不包括它们。通过java -jar artifact.jargradle bootRun 运行应用程序没有任何问题。

感谢@fateddy 帮助解决问题。

【讨论】:

    【解决方案2】:

    您可以配置您的 IDE 以在 Build/Launch 之前调用 process-resources maven 目标,这将导致 git.properties 文件和 build-info.properties 文件在应用程序启动之前生成。

    我使用 Maven,但 Gradle 应该可以进行类似的配置。

    【讨论】:

    • 谢谢,这也适用于从 Gradle 的 IDE 运行
    • 是的。 Gradle 有任务processResourcesprocessTestResourcesprocessItestResources。不要用 IDE 运行,用 Gradle 运行。
    【解决方案3】:

    对于 IntelliJ IDEA,您可以在设置(首选项)| 中启用 将 IDE 构建/运行操作委托给 Gradle 选项构建、执行、部署 |构建工具 |摇篮 |跑步者标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      • 2018-10-15
      相关资源
      最近更新 更多