8

I'm using Gradle with Spring Boot 2.0.0.M7 and have the following plugins applied:

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 dependency is also there. git.properties files is generated correctly to build/main/resoures directory. I've also added property management.info.git.mode=full. Due to official docs, git information should be added to /info endpoint automatically with GitInfoContributor. However none of the above helps and /info endpoint returns empty JSON instead - {}. Any ideas on how this can be fixed?

UPDATE 1: What I've found so far is that if I manually copy git.properties to out/resources, this way it would work, but they are not put there for some reason.

UPDATE 2: When I run with gradle bootRun it works, however when I start it from Intellij IDEA our run gradle clean build which runs the test which checks if those properties are displayed on /info endpoint - it doesn't work.

yyunikov
  • 5,719
  • 2
  • 43
  • 78
  • seems as if you need to apply the plugin as well (otherwise the git.properties file is not bundled within the jar): `apply plugin: "com.gorylenko.gradle-git-properties"` – fateddy Jan 07 '18 at 10:24
  • Unfortunately that doesn't help. With Gradle > 2.1, apply section can be skipped if you specify `plugins` section as far as I know. https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties – yyunikov Jan 07 '18 at 10:29
  • Gets the `git.properties` file packaged with the jar? – fateddy Jan 07 '18 at 10:32
  • Yes, I see it packaged in `BOOT-INF/classes` dir in jar. Interesting fact I've just found, is that with `gradle bootRun` it works, however when I start it from Intellij IDEA our run `gradle clean build` which runs the test which checks if those properties are displayed on /info - it doesn't work. – yyunikov Jan 07 '18 at 10:38
  • So I think it gets packaged and then it works. However before packaging like running from IDE or running from tests - it doesn't. – yyunikov Jan 07 '18 at 10:40
  • Running from the IDE might not work - because usually this tools package the artifact into a separate (other than gradle/maven( directory for execution. – fateddy Jan 07 '18 at 10:46
  • @fateddy ok, that's sad. Thanks for the answer, I'll keep digging, maybe there is any solution at least for checking that from tests. – yyunikov Jan 07 '18 at 10:51

3 Answers3

10

The problem was running the app from IDE. As the properties are generated on the phase when JAR is assembled, they were not included. Running the application via java -jar artifact.jar or gradle bootRun works without any issues.

Thanks @fateddy for help on resolving the issue.

yyunikov
  • 5,719
  • 2
  • 43
  • 78
5

You can configure your IDE to call the process-resources maven goal, prior to the Build/Launch, this will cause the git.properties file and build-info.properties files to be generated prior to the application launching.

I use Maven, but a similar configuration should be possible for Gradle.

IntelliJ Build/Run Configuration

eztinkerdreams
  • 381
  • 2
  • 3
  • 17
3

For IntelliJ IDEA, you can enable Delegate IDE build/run actions to Gradle option in Settings (Preferences) | Build, Execution, Deployment | Build Tools | Gradle | Runner tab.