Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 3.91 KB

File metadata and controls

110 lines (80 loc) · 3.91 KB

Running your application with Gradle

To run your application without first building an archive use the bootRun task:

$ ./gradlew bootRun

The bootRun task is an instance of {boot-run-javadoc}[BootRun] which is a JavaExec subclass. As such, all of the {gradle-dsl}/org.gradle.api.tasks.JavaExec.html[usual configuration options] for executing a Java process in Gradle are available to you. The task is automatically configured to use the runtime classpath of the main source set.

By default, the main class will be configured automatically by looking for a class with a public static void main(String[]) method in directories on the task’s classpath.

The main class can also be configured explicitly using the task’s main property:

Groovy
link:../gradle/running/boot-run-main.gradle[role=include]
Kotlin
link:../gradle/running/boot-run-main.gradle.kts[role=include]

Alternatively, the main class name can be configured project-wide using the mainClassName property of the Spring Boot DSL:

Groovy
link:../gradle/running/spring-boot-dsl-main-class-name.gradle[role=include]
Kotlin
link:../gradle/running/spring-boot-dsl-main-class-name.gradle.kts[role=include]

By default, bootRun will configure the JVM to optimize its launch for faster startup during development. This behavior can be disabled by using the optimizedLaunch property, as shown in the following example:

Groovy
link:../gradle/running/boot-run-disable-optimized-launch.gradle[role=include]
Kotlin
link:../gradle/running/boot-run-disable-optimized-launch.gradle.kts[role=include]

If the {application-plugin}[application plugin] has been applied, its mainClassName property must be configured and can be used for the same purpose:

Groovy
link:../gradle/running/application-plugin-main-class-name.gradle[role=include]
Kotlin
link:../gradle/running/application-plugin-main-class-name.gradle.kts[role=include]

Passing arguments to your application

Like all JavaExec tasks, arguments can be passed into bootRun from the command line using --args='<arguments>' when using Gradle 4.9 or later. For example, to run your application with a profile named dev active the following command can be used:

$ ./gradlew bootRun --args='--spring.profiles.active=dev'

See {gradle-api}/org/gradle/api/tasks/JavaExec.html#setArgsString-java.lang.String-[the javadoc for JavaExec.setArgsString] for further details.

Reloading resources

If devtools has been added to your project it will automatically monitor your application for changes. Alternatively, you can configure bootRun such that your application’s static resources are loaded from their source location:

Groovy
link:../gradle/running/boot-run-source-resources.gradle[role=include]
Kotlin
link:../gradle/running/boot-run-source-resources.gradle.kts[role=include]

This makes them reloadable in the live application which can be helpful at development time.