Thanks. I ended up with the second option, which works just great.
Regarding the first option, I had to add non-null owner in the ActionClosure
constructor:
import gradle.api.Action;
import groovy.lang.Closure;
public class ActionClosure<T> extends Closure<Object> {
private final Action<T> action;
public ActionClosure(Object owner, Action<T> action) {
super(owner);
this.action = action;
}
@Override
public Object call() {
action.execute((T) getDelegate());
return null;
}
}
and I passed project as owner (though I think it could have been anything). Otherwise I got IllegalArgumentException
saying “Value is null”.