How to use different dependencies for a particular build type

I would like to add certain dependencies only when a particular task is being executed. E.g I have a specific task to create a production build.

When I run this production build I want to include different slf4j bindings then I use in test build.

I’m currently using:

gaeRun {

gradle.taskGraph.whenReady { taskGraph ->

if (taskGraph.hasTask(":gaeRun")) {

project.dependencies.add(“compile”, “org.slf4j:slf4j-log4j12:${slf4jVersion}”) // log4j binding

project.dependencies.add(“compile”, “org.slf4j:jul-to-slf4j:${slf4jVersion}”) //java.util.logging bridge

}

} }

gaeUpdate {

gradle.taskGraph.whenReady { taskGraph ->

if (taskGraph.hasTask(":gaeUpdate")) {

project.dependencies.add(“compile”, “org.slf4j:slf4j-jdk14:${slf4jVersion}”) // commons-logging bridge

project.dependencies.add(“compile”, “org.slf4j:log4j-over-slf4j:${slf4jVersion}”) // java.util.logging binding

}

} }

Is this the best approach?