0

how does Gradle detect optional commands? I was hoping that I can do some additional tasks with CreateStartScript to add some classpath based on staging and prod, but I'm not sure what to do. Can anyone point me to the right direction? Say something like

"./gradlew clean build --staging" or "./gradlew clean build --prod"

or something like

"./gradlew clean build staging" or "./gradlew clean build prod"

Kevin Tan
  • 1,038
  • 8
  • 19
  • 1
    you can use "project properties" (see https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties ) , like `./gradlew clean build -Penvironment=staging`, and then refer to this propery in your build script for configuring your task accordingly ( `project.findProperty('environment')` ) – M.Ricciuti May 16 '19 at 19:21

1 Answers1

0

Detect environment in build.gradle like this.

if (grails.util.Environment.current.name.contains("dev")) {

And then build specific environment like this.

gradle -Dgrails.env=dev assemble
Arjang
  • 731
  • 1
  • 10
  • 19
  • It's not exactly a Grails question. It's more of a Spring Boot question. – Kevin Tan May 16 '19 at 10:56
  • See this post to detect active environment. https://stackoverflow.com/questions/28392231/how-to-determine-programmatically-the-current-active-profile-using-spring-boot – Arjang May 16 '19 at 11:10