Throwable (Throwable e) { if (e instanceof BuildActionFailureException) { return extractCause(e.getCause()); } // Exceptions returned by Gradle TAPI have classes loaded by a separate classloader Class<? extends Throwable> exceptionClass = e.getClass(); if (exceptionClass.getName().equals(ProjectConfigurationException.class.getName())) { try { //noinspection unchecked List<Throwable> causes = (List<Throwable>)exceptionClass.getMethod("getCauses").invoke(e); return causes.get(0); } catch (Throwable ignore) { return e; } } return e; }