Springboot Gradle插件不适用于Eclipse [英] Springboot Gradle Plugin not working with Eclipse

查看:167
本文介绍了Springboot Gradle插件不适用于Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

当我使用此springboot插件时,我的Java项目无法在Eclipse中运行 springboot-gradle-插件问题
要查看此问题,您需要使用Eclipse运行该项目(我使用Eclipse 2019-09运行它)

这个项目做什么

此Java项目对该插件使用gradle bootBuildInfo "的Gradle任务,并在运行此任务时创建此文件 META-INF/build-info.properties .
在Java中,运行App时,springboot会自动加载并读取 META-INF/build-info.properties 来创建一个bean.

Eclipse的问题

当我在终端中使用gradle进行构建并运行生成的jar文件时,所有这些工作正常,但是当我通过Eclipse运行我的应用程序时,此工作不起作用.
它不会创建文件 META-INF/build-info.properties ,并且当springboot尝试加载该文件时,由于找不到文件而引发了bean找不到异常. /strong>

找到解决方法

如果执行以下操作之一,则该项目将运行:
-在src/main/resources文件夹下手动创建META-INF/build-info.properties
-在build/resources/main文件夹下手动创建META-INF/build-info.properties

这些方法都不是可取的,因为它不会自动更新build-info.properties

解决方案

Gradle的Eclipse支持使您可以配置在同步或构建项目时应运行的任务.它需要Gradle 5.4或更高版本以及Buildship(提供Gradle支持的Eclipse插件)3.1或更高版本.

您可以将bootBuildInfo配置为在Eclipse构建项目时运行,方法是将以下内容添加到build.gradle:

eclipse {
    autoBuildTasks bootBuildInfo
}

您可以在此博客文章中了解更多有关功能的信息. /p>

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

解决方案

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.

这篇关于Springboot Gradle插件不适用于Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆