1

我阅读了 Spring Boot 文档,发现至少有两种方法可以设置主类:

bootRepackage {
    mainClass = 'demo.Application'
}

springBoot {
    mainClass = "demo.Application"
}

我应该使用哪一个,或者它们都需要用于不同的任务?我不想重复自己。

4

2 回答 2

2

在 Gradle 术语中,springBoot是一个扩展。当您使用它来配置主类时,您正在为项目中的每个重新打包任务配置它。另一方面bootRepackage是引用单个重新打包任务,因此您只需mainClass为该任务配置。

我应该使用哪一个,或者它们都需要用于不同的任务?

如果您只有一个重新打包任务(默认情况下),这是个人喜好问题。

如果您已经配置了额外的重新打包任务,您最好在每个单独的任务上配置它,而不是使用springBoot扩展。如果您混合使用两者,则单个重新打包任务的设置将优先于您使用springBoot.

于 2016-07-01T11:03:32.947 回答
0

这是来自 springBoot 插件的文档:

The gradle plugin automatically extends your build script DSL with a 
springBoot element for global configuration of the Boot plugin. Set 
the appropriate properties as you would with any other Gradle 
extension (see below for a list of configuration options):

下面是一个配置 bootRepackage 插件的 mainClass 元素的示例:

The main class that should be run. If not specified, and you 
have applied the application plugin, the mainClassName project 
property will be used. If the application plugin has not been 
applied or no mainClassName has been specified, the archive will 
be searched for a suitable class. "Suitable" means a unique class 
with a well-formed main() method (if more than one is found the 
build will fail). If you have applied the application plugin, 
the main class can also be specified via its "run" task 
(main property) and/or its "startScripts" task 
(mainClassName property) as an alternative to using the 
"springBoot" configuration.

换句话说,这两者是相同的。

于 2016-07-01T11:01:45.263 回答