2

THE problem

My java project doesn't run in Eclipse when I use this springboot plugin springboot-gradle-plugin
It throws this exception

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
[2020-02-09 15:45:27.825] - 12256 GRAVE [main] --- org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter: 

***************************
APPLICATION FAILED TO START
***************************

Description:

Constructor in com.example.demo.VersionController required a bean of type 'org.springframework.boot.info.BuildProperties' that could not be found.
    - Bean method 'buildProperties' in 'ProjectInfoAutoConfiguration' not loaded because @ConditionalOnResource did not find resource '${spring.info.build.location:classpath:META-INF/build-info.properties}'

A sample project with the issue

A sample repository with this issue can be found here:springboot-gradle-plugin-issue
To see this issue you need to run this project with Eclipse (I run it with eclipse 2019-09)

What this project does

This java project uses gradle with this plugin spring-boot-gradle-plugin.
This project prints in console the application version declared in my build.gradle file. In my gradle.build file I include this lines:

springBoot {
    buildInfo()
}

This lines all it does is adds a Gradle Task called 'bootBuildInfo' into gradle and while running this task it creates this file META-INF/build-info.properties.
In Java, when running the App, springboot automatically loads and reads META-INF/build-info.properties to create a bean.

The problem with Eclipse

All this works when I build with gradle in a terminal and run the generated jar file, but it does not work when I run my application through Eclipse.
It doesn't create the file META-INF/build-info.properties and when springboot tries to load it up throws a bean not found exception because it couldn't find the file.

Workarounds found

The project will run if I do one of the followings:
- manually create META-INF/build-info.properties under src/main/resources folder
- manually create META-INF/build-info.properties under build/resources/main folder

None of this aproaches are desired because it doesn't updates build-info.properties automatically

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
aee
  • 543
  • 3
  • 14

1 Answers1

3

Gradle’s Eclipse support allows you to configure tasks that should be run when a project is synchronized or built. It requires Gradle 5.4 or later and Buildship (the Eclipse plugin that provides Gradle support) 3.1 or later.

You can configure bootBuildInfo to run whenever Eclipse builds the project by adding the following to build.gradle:

eclipse {
    autoBuildTasks bootBuildInfo
}

You can learn more about the functionality in this blog post.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Hello. Thanks for the answer. autoBuildTasks executes a specified task everytime I make change to a file withing Eclipse. Thanks to this the build-info.properties is generated and updated. But, the problem is that this file is generated outside my classpath (here build\resources\main\META-INF\build-info.properties) and when I run the application in the IDE doesn't work. – aee Feb 11 '20 at 20:43
  • You could either run the application in your IDE via the Gradle integration (using the `bootRun` task) or you could modify the classpath that Eclipse uses. – Andy Wilkinson Feb 12 '20 at 10:47