gradle: use 'doLast' when defining tasks

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
gradle: check that directory creation succeeds

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>