// alternatively, we could return project.files(Runnable)
// would differ in at least the following ways: 1. live 2. no autowiring
return new LazilyInitializedFileCollection() {
@Override
public FileCollection createDelegate() {
GroovyJarFile groovyJar = findGroovyJarFile(classpath);
if (groovyJar == null) {
throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", classpath));
}
if (groovyJar.isGroovyAll()) {
return project.files(groovyJar.getFile());
}
if (project.getRepositories().isEmpty()) {
throw new GradleException("Cannot infer Groovy class path because no repository is declared for the project.");
}
String notation = groovyJar.getDependencyNotation();
List<Dependency> dependencies = Lists.newArrayList();
// project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier
dependencies.add(project.getDependencies().create(notation));
if (groovyJar.getVersion().getMajor() >= 2) {
// add groovy-ant to bring in Groovydoc
dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:")));
}
return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[dependencies.size()]));
}