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"
}
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.
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/ .
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'
}
}
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With