Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a gradle task that will execute bootRun with a specific profile?

I essentially want to create a task in gradle that executes the command

gradle bootRun -Dspring.profiles.active=test

This command does exactly what I want it to do if executed from the command line but I have had no luck trying to use type:Exec on a task and also no luck passing in System properties

I don't really want to make this into an external command that the user needs to know about to run. I would like it to show up under tasks/other.

My closest attempt so far:

task bootRunTest() {
    executable "gradle"
    args "-Dspring.profiles.active=test bootRun"
 }
like image 309
dszopa Avatar asked Oct 03 '16 19:10

dszopa


People also ask

What is bootRun Gradle task?

The Spring Boot gradle plugin provides the bootRun task that allows a developer to start the application in a “developer mode” without first building a JAR file and then starting this JAR file. Thus, it's a quick way to test the latest changes you made to the codebase.

How do I create a Gradle profile?

To run the gradle-profiler app to profile a build use: > gradle-profiler --profile <name-of-profiler> --project-dir <root-dir-of-build> <task>... The app will run the build several times to warm up a daemon, then enable the profiler and run the build. Once complete, the results are available under profile-out/ .


3 Answers

The task I was trying to create wound up being this:

task bootRunTest(type: org.springframework.boot.gradle.run.BootRunTask, dependsOn: 'build') {
    group = 'Application'
    doFirst() {
        main = project.mainClassName
        classpath = sourceSets.main.runtimeClasspath
        systemProperty 'spring.profiles.active', 'test'
    }
}
like image 77
dszopa Avatar answered Sep 22 '22 01:09

dszopa


Here is how you set the properties for the task you wish to run, in this case bootRun

add inside of Build.gradle

bootRun {
        systemProperty "spring.profiles.active", "test,qa,ect"
}

Then from the command line

gradle bootRun
like image 30
Zergleb Avatar answered Sep 21 '22 01:09

Zergleb


You can also do it by setting the OS variable, SPRING_PROFILES_ACTIVE, to the specific profile.

For eg:

SPRING_PROFILES_ACTIVE=dev gradle clean bootRun
like image 30
Rothin Sen Avatar answered Sep 19 '22 01:09

Rothin Sen