public static File getClasspathForClass(Class<?> targetClass) {
URI location;
try {
location = targetClass.getProtectionDomain().getCodeSource().getLocation().toURI();
} catch (URISyntaxException e) {
throw new UncheckedIOException(e);
}
if (!location.getScheme().equals("file")) {
throw new GradleException(String.format("Cannot determine Gradle home using codebase '%s'.", location));
}
return new File(location.getPath());