Search code examples
gradlemicronaut

How do you run micronaut from gradle with local properties


I want to run Micronaut server from Gradle command line with "local" environment variables. The regular command

.\gradlew.bat run

will use default variables defined in application.yml file. I want to override some of them with values for my local environment and therefore need to specify system property micronaut.environments=local to use overriding values from application-local.yml file.

.\gradlew.bat run -Dmicronaut.environments=local

The command above won't work as Gradle will take only -Dmicronaut for the system property and the rest ".environments=local" will be considered as another task name:

Task '.environments=local' not found in root project 'abc'

What would be the correct way to pass such system property to the java process?


Solution

  • Command below works for unix, probably it should work also for windows:

    MICRONAUT_ENVIRONMENTS=local gradle run
    

    or use gradle wrapper

    MICRONAUT_ENVIRONMENTS=local .\gradlew.bat run
    

    P.S. also, you can find the same approach for Spring Boot