Dev mode dependency for gradle in IDEA

2.1k Views Asked by At

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.

1

There are 1 best solutions below

1
On

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.