Gradle exclude dependency from a task

I have a task “vaadinCompileWidgetset” which won’t work if javax-validation-1.1 is on classpath (it depends on javax-validation-1.0). The problem is, my build depends on 1.1 so I can’t exclude the artifact from the build.

Is it possible to exclude the dependency or force 1.0 on the vaadinCompileWidgetset task only?

This question is also asked on stackoverflow:

What’s the type of your custom class?