Or Betzalel
Or Betzalel

Reputation: 2597

Gradle build parameters in development environment

I have Spring Boot project with Gradle and I had to put some parameters in the gradle file so I can build to project with different environments.

So for example I use

gradlew build docker -Penv_name=prod

And I get a custom docker name

docker {
  dependsOn build
  name "gcr.io/app-${env_name}/app"
}

It's all good but the problem is that I get errors from intelliJ

Could not get unknown property 'env_name' for root project

Adding def env_name = "" obviously solves the problem.

Is there a way to define env_name only if it's not already defined, or maybe set default value to it somehow?

Upvotes: 2

Views: 471

Answers (1)

lealceldeiro
lealceldeiro

Reputation: 14958

Yes, you can define some default values in a gradle.properties file in the root directory of your Spring Boot project (see sample from a demo project of mine).

In there you can define all gradle properties, something like

env_name = dev

When you run the gradle command from the command line with this parameter set, it is overridden and when the command is ran from IntelliJ IDEA the default parameter is used.

Further readings

Upvotes: 1

Related Questions