Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 578
Aziris Avatar asked Jul 02 '19 10:07

Aziris


People also ask

How do I run a Micronaut in Gradle?

6. Running the Application. To run the application, use the ./gradlew run command, which starts the application on port 8080.

How do I run a script in Gradle?

Running Gradle Commands To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … ​ e.g. gradlew clean allTests.

What is the use of Gradle properties file?

The gradle. properties helps with keeping properties separate from the build script and should be explored as viable option. It's a good location for placing properties that control the build environment.


2 Answers

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

like image 127
tsarenkotxt Avatar answered Oct 16 '22 12:10

tsarenkotxt


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
like image 21
Ben Lucchesi Avatar answered Oct 16 '22 13:10

Ben Lucchesi