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

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

gradle bootRun -Dspring.profiles.active=test

This command does exactly what I want to do if it is executed from the command line, but I could not use the type: Exec for the task, and there is also no luck in the System Properties

I really do not want to do this in an external command that the user needs to know about the launch. I would like it to appear under tasks / others.

My nearest attempt:

task bootRunTest() {
    executable "gradle"
    args "-Dspring.profiles.active=test bootRun"
 }
+4
source share
3 answers

The task that I was trying to create turned out to be 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'
    }
}
+3
source

, , bootRun

Build.gradle

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

gradle bootRun
0

You can also do this by setting the special OS profile , SPRING_PROFILES_ACTIVE .

For instance,

SPRING_PROFILES_ACTIVE=dev gradle clean bootRun
0
source

Source: https://habr.com/ru/post/1656623/


All Articles