Spring Boot gradlewコマンドの使い方
- 作成日 2020.06.22
- 更新日 2020.07.17
- Gradle Spring Boot
- Spring Boot

Spring Initializrを使って作成したSpring Bootプロジェクトのwindows用の「gradlew.bat」を使用してgradlewコマンド( Gradle Wrapper スクリプト )の実行手順を記述してます。
環境
- OS windows10 pro 64bit
- Spring Boot 2.2.6
gradlew tasks
gradlewコマンドはbuild.gradle( .kts → kotlin )と同一階層で実行してください。

gradlew tasksを実行すると、実行できるタスクの一覧が表示されます。
gradlew tasks
<出力結果>
> 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.
kotlinDslAccessorsReport - Prints the Kotlin code for accessing the currently available project extensions and conventions.
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.
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.
To see all tasks and more detail, run gradlew tasks --all
To see more detail about a task, run gradlew help --task <task>
gradlew build
gradlew buildを実行するとbuildが開始され「build\libs」配下にjarが作成されます。
gradlew build

下記のコマンドで実行可能です。
cd build\libs
java -jar demo-0.0.1-SNAPSHOT.jar
<出力結果>
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.7.RELEASE)
2020-05-13 18:27:11.891 INFO 11796 --- [ main] com.example.demo.DemoApplicationKt : Starting DemoApplic
gradlew bootrun
gradlew bootrunを実行するとSpring Bootプロジェクトが実行されます。
gradlew bootrun
<出力結果>
> Task :bootRun
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.7.RELEASE)
2020-05-13 18:31:57.896 INFO 18360 --- [ restartedMain] com.example.demo.DemoApplicationKt
gradlew clean
実行するとbuildした際に生成されたファイルが削除されます。
gradlew clean
buildフォルダが削除される。

-
前の記事
Laravel7 複数のカラムを指定してorder byを実行する手順 2020.06.22
-
次の記事
Laravel7 axios(アクシオス)を使用してWebApiからデータを取得する 2020.06.23
コメントを書く