LoginSignup
3
3

More than 3 years have passed since last update.

SpringBootプロジェクトのGradleタスクを眺める

Last updated at Posted at 2020-04-30

Gradleのタスクを眺める

下のコマンドでタスクの一覧を見ることができる。

.\gradlew.bat task --all

下のように表示される。

> Task :tasks

------------------------------------------------------------
Tasks runnable from root project
------------------------------------------------------------

Application tasks
-----------------
bootRun - Runs this project as a Spring Boot application.

Build tasks
-----------
assemble - Assembles the outputs of this project.
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'demo'.
components - Displays the components produced by root project 'demo'. [incubating]
dependencies - Displays all dependencies declared in root project 'demo'.
dependencyInsight - Displays the insight into a specific dependency in root project 'demo'.
dependencyManagement - Displays the dependency management declared in root project 'demo'.
dependentComponents - Displays the dependent components of components in root project 'demo'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'demo'. [incubating]
outgoingVariants - Displays the outgoing variants of root project 'demo'.
projects - Displays the sub-projects of root project 'demo'.
properties - Displays the properties of root project 'demo'.
tasks - Displays the tasks runnable from root project 'demo'.

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

Other tasks
-----------
compileJava - Compiles main Java source.
compileTestJava - Compiles test Java source.
prepareKotlinBuildScriptModel
processResources - Processes main resources.
processTestResources - Processes test resources.

Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.

ビルド関連のタスク

ビルドタスクだけでも、9つもある。
javaプラグイン由来のタスクとorg.springframework.bootプラグイン由来のタスクがある。

Build tasks
-----------
assemble - Assembles the outputs of this project.
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.

タスクの依存関係は、下の画像を見れば分かりやすい。

javaPluginTasks.png

https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_tasks から転載)

assembleタスク

jarファイルを生成した上で、さらにarchivesで設定されている生成物も生成する。
zipを生成するタスクを作って、archivesに追加しておけば、ビルド時にカスタムのzipファイルを作成することもできる。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar
> Task :jar SKIPPED
> Task :assemble

bootJarタスク

メインクラスとその全ての依存関係を含む、実行可能なjarファイルを生成するタスク。
テストを実行せず、jarファイルだけ欲しいときは、このタスクを実行する。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar

buildタスク

普通にビルドするときは、このタスクを実行する。マルチプロジェクト時は、現在のプロジェクトだけをビルドする。テストも実行され、build\reportsディレクトリの下にテストリポートが生成される。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar
> Task :jar SKIPPED
> Task :assemble
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test
2020-04-30 13:26:22.615  INFO 5520 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

> Task :processTestResources NO-SOURCE
> Task :testClasses

buildDependentsタスク

マルチプロジェクト時のビルドのやり方の一つ。buildDependentsでビルドすれば、今のプロジェクトにtestRuntimeClasspath設定の依存関係を持っている全てのプロジェクトもビルドされる。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar
> Task :jar SKIPPED
> Task :assemble
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test
2020-04-30 13:27:15.725  INFO 16828 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

> Task :check
> Task :build
> Task :buildDependents

buildNeededタスク

マルチプロジェクト時のビルドのやり方の一つ。今のプロジェクトだけではなく、そのプロジェクトがtestRuntimeClasspath設定で依存している全てのプロジェクトもビルドされる。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar
> Task :jar SKIPPED
> Task :assemble
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test
2020-04-30 13:27:40.483  INFO 9032 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

> Task :check
> Task :build
> Task :buildNeeded

classesタスク

Javaのmainのソースコードをコンパイルし、クラスファイルを作成するタスク。
IntelliJにはデコンパイラが付いていて、IDE上でクラスファイルの中身を解析できるが、実体はコンパイルされたバイトコード。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes

cleanタスク

buildディレクトリを削除するタスク。

アウトプット

> Task :clean

jarタスク

mainのソースセットをコンパイルし、jarファイルを生成する。
今回のプロジェクトでは、bootJarタスクがあるからか、jarタスクはスキップされている。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :jar SKIPPED

testClassesタスク

Javaのtestのソースコードをコンパイルし、テストのクラスファイルを作成するタスク。

アウトプット

> Task :compileJava
> Task :processResources
> Task :classes
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3