0

I want to add dependency on spring-boot-devtools but only for development. I try to achieve this by having this snippet in my build.gradle:

if (project.hasProperty('use-spring-boot-devtools')) {
    compile 'org.springframework.boot:spring-boot-devtools'
}

Then I can define in my ~/.gradle/gradle.properties

use-spring-boot-devtools = true

Unfortunately this doesn't work when I run import project in IDEA. I would like to use answer to related question but still can't figure out how to define environment variable that will affect gradle inside IDEA.

Alex Dvoretsky
  • 938
  • 9
  • 21

1 Answers1

2

Do not use hyphens to concat your key in the gradle.properties. Instead define it in camel case:

useSpringBootDevtools=true

And for your build.gradle file, use the following syntax for your conditional dependency:

if(useSpringBootDevtools.toBoolean())
{
    // your conditional dependency here
}

Make sure to append toBoolean() to your key since it's not casted automatically by Gradle.

UnlikePluto
  • 3,101
  • 4
  • 23
  • 33
  • 1
    this really helped me a lot. I have a requirement to use a common project as dependency. in dev/my machine I simple added common project to build path and add conditional dependency like above only for prod. – Vishal Patel Aug 11 '19 at 18:24