7

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?

Szymon Stepniak
  • 32,284
  • 9
  • 78
  • 108
Aziris
  • 107
  • 1
  • 8

2 Answers2

4

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

tsarenkotxt
  • 2,300
  • 2
  • 17
  • 35
  • 1
    Thanks, that was it, totally overlooked this approach, thought I have to define the variable with the gradle command itself. – Aziris Jul 12 '19 at 06:40
  • This also works in IntelliJ by specifing "environment variables" in the run configuration like "MICRONAUT_ENVIRONMENTS=local" – H3ADLESS Feb 15 '21 at 11:08
3

My approach is to add a gradle task.

task runLocal(type: JavaExec) {
   classpath = sourceSets.main.runtimeClasspath
   main = "dontdrive.Application"
   jvmArgs '-Dmicronaut.environments=local'
}

then start with:

./gradlew runLocal