How to pass system property to Gradle task

前端 未结 14 2501
别跟我提以往
别跟我提以往 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 02:46

    This works:

    SPRING_PROFILES_ACTIVE=production ./gradlew app-service:bootRun

    0 讨论(0)
  • 2020-12-08 02:47

    with run command you can add to build file run { systemProperties = System.properties } and start with gradle run -Dspring.profiles.active=local

    0 讨论(0)
  • 2020-12-08 02:52
    task local {
        run { systemProperty "spring.profiles.active", "local" }
    }
    
    bootRun.mustRunAfter local
    

    Then run gradle command as:

    gradle bootRun local
    
    0 讨论(0)
  • 2020-12-08 02:52
    // defualt value
    def profiles = 'dev'
    
    bootRun {
        args = ["--spring.profiles.active=" + profiles]
    }
    

    Then you can simply pick a specific version when starting a gradle task, like

    ./gradlew bootRun -P dev
    

    "dev" is gonna to take place "prod"

    0 讨论(0)
  • 2020-12-08 02:55

    I know I'm late here... but I recently faced this exact issue. I was trying to launch bootRun with spring.profiles.active and spring.config.location set as system properties on the command line.

    So, to get your command line "magic" to work, simply add this to your build.gradle

    bootRun {
        systemProperties System.properties
    }
    

    Then running from the command line...

    gradle -Dspring.profiles.active=local bootRun
    

    Will set local as the active profile, without needing to define a separate task simply to add the env variable.

    0 讨论(0)
  • 2020-12-08 02:56

    According to the spring-boot-gradle-plugin documentation you should be able to pass arguments like this

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

    Seems like this is a new gradle feature since 4.9. I used it in my project and it worked out of the box.

    0 讨论(0)
提交回复
热议问题