How to pass system property to Gradle task

前端 未结 14 2503
别跟我提以往
别跟我提以往 2020-12-08 02:17

I\'m using Gradle spring-boot plugin and I need to select a spring active profile for the test run.

How do I pass spring.profiles.active sy

相关标签:
14条回答
  • 2020-12-08 03:09

    There is no generic way to pass system properties to a task. In a nutshell, it's only supported for tasks that fork a separate JVM.

    The bootRunLocal task (as defined above) will not execute in a separate JVM, and calling execute() on a task isn't supported (and would have to happen in the execution phase in any case). Tests, on the other hand, are always executed in a separate JVM (if executed by a Test task). To set system properties for test execution, you need to configure the corresponding Test task(s). For example:

    test {
        systemProperty "spring.profiles.active", "local"
    }
    

    For more information, see Test in the Gradle Build Language Reference.

    0 讨论(0)
  • 2020-12-08 03:11

    For gradle 2.14 below example works. I have added as below.
    When System.properties['spring.profiles.active'] is null then default profile is set.

      bootRun {
           systemProperty 'spring.profiles.active', System.properties['spring.profiles.active']
        }
    

    command line example

    gradle bootRun -Dspring.profiles.active=dev
    
    0 讨论(0)
提交回复
热议问题