DependencyHandler not java friendly


(Lance Java) #1

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:

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!


(Mark Vieira) #2

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.


(Lance Java) #3

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.