# DependencyHandler not java friendly

**URL:** <https://discuss.gradle.org/t/dependencyhandler-not-java-friendly/19161>\
**Category:** Help/Discuss\
**Created:** [August 24, 2016, 12:27pm UTC](https://discuss.gradle.org/t/dependencyhandler-not-java-friendly/19161 "2016-08-24T12:27:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [August 24, 2016, 12:27pm UTC](https://discuss.gradle.org/t/dependencyhandler-not-java-friendly/19161/1 "2016-08-24T12:27:43Z")

</div>

I’d prefer to write my plugins in java instead of groovy and I find that `Action` is far more java friendly than `Closure`

The CopySpec api allows both `Action` and `Closure`. Eg:

```java
CopySpec from(Object sourcePath, Closure c)
CopySpec from(Object sourcePath, Action<? super CopySpec> configureAction)

```

Can I request that `Action` methods are also offered on the `DependencyHandler` Interface for `add()` and `create()`?

I noticed there’s a `ClosureBackedAction` but it seems there’s no `ActionBackedClosure`. Note: I’m aware of groovy’s `MethodClosure` which I could use but it feels dirty!

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [August 24, 2016, 3:03pm UTC](https://discuss.gradle.org/t/dependencyhandler-not-java-friendly/19161/2 "2016-08-24T15:03:32Z")

</div>

Yes, we should definitely be doing this. We are doing a sweep of the API for stuff like this. This impacts the Kotlin work as well. For now I’d suggest instead doing `create()`, modifying the returned dependency and then passing to `add()`. It’ll be much less messy than using a `MethodClosure`.

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [August 24, 2016, 3:42pm UTC](https://discuss.gradle.org/t/dependencyhandler-not-java-friendly/19161/3 "2016-08-24T15:42:36Z")

</div>

Ah, ok… I hadn’t realised I could call create() without the closure and mutate the `Dependency`. I thought it was atomic/immutable. Will do that, thanks.
