2016-07-01 15 views
1

私は春のブートマニュアルを読み、私が見るメインクラスを設定するには、少なくとも2つの方法があります。一つは、私が使うべきか、彼らは両方の異なるタスクのために必要とされるGradleでSpring Bootアプリケーションのメインクラスを設定する方法は?

bootRepackage { 
    mainClass = 'demo.Application' 
} 

springBoot { 
    mainClass = "demo.Application" 
} 

は?私は自分自身を繰り返すことはしません。

答えて

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. 

これら二つが同一です。

1

Gradle用語では、springBootが拡張です。メインクラスを設定するときは、プロジェクトの再パッケージ化タスクごとに設定します。一方、bootRepackageは単一の再パッケージ化タスクを参照しているため、その1つのタスクに対してmainClassを設定するだけです。

私はどちらを使うべきですか、どちらが別々の仕事に必要ですか?

(デフォルトの場合と同様に)単一の再パッケージ化タスクしかない場合、これは個人的な好みの問題です。

追加の再パッケージ化タスクを設定した場合は、springBoot拡張子を使用するのではなく、個々のタスクで構成する方がよいでしょう。この2つを混在させて使用する場合は、個々の再パッケージ化タスクの設定が、springBootを使用して設定したものよりも優先されます。

関連する問題