I wrote a gradle plugin where I do expect to access sources of the project and generate some files. Everything works when I run my project from Java, however when I try to do the same via plugin it does not work. It does not see the sources of the project.
Is it true, that in gradle, sources are not visible to buildscript and therefore to plugin as well? Is it possible to make them available for the plugin?
This class is used to get the list of classes.
public class ClassFinder {
private final List<? extends Class<?>> classes;
public ClassFinder(String packageToScan) {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(".*")));
Set<BeanDefinition> classes = provider.findCandidateComponents(packageToScan);
this.classes = classes.stream()
.map(bean -> {
try {
return Class.forName(bean.getBeanClassName());
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
})
.collect(Collectors.toList());
}
...
}
I can use it either in main
method or in plugin. In main
it finds all the classes in my current project. In plugin it does not find anything (except libraries).