New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception with multi-maven builds (exclude current folder from scanned classpath) #55
Comments
I think you should use the context class loader instead, i.e. Reflections uses the |
Hi Martin, thanks for your reply. I tried using the context class loader, but unfortunately then it returns only 13 urls:
I believe those are the maven core libraries. Meanwhile If I use the static classloader it returns 167 jars (all my dependencies in the pom.xml + the folder that I mentioned |
Then try with |
Hi Martin, thanks for the suggestion. I thought of doing so but unfortunately I can't :( .. I'm making a platform which I will be giving to customer, and I don't know what will be classA's name in my customer's project. I want to be able to find class A, classB and also if there's a classC defined by the customer. I really need to scan ALL the classpath to find ALL the classes that have the given annotation. Plus it definitely looks like a bug in reflections to recursively scan the subdirectories. As I said my project has more than 50 modules, each one having at least 5 subdirectories. This is super inefficient to scan all of them, and later not being able to use what you scanned (classB is not in the classpath). |
Let's see what response you'll get at Maven mailing lists (I've noticed your question there). Which version of Reflections do you use ? |
0.9.9 but I don't think it's a problem of maven... From what I can see maven will invoke |
This thread: https://community.oracle.com/thread/2456122 explains that it's always been like that (the current working directory is getting added to the classpath). So i guess now it's more an issue of |
You should avoid scanning all urls, but only those that contains classes whose fqn starts with your clients package prefix(es), and these must be known a priori. |
Hello,
I have the following project setup:
and I'm building it with maven, and I use an
AbstractProcessor
during compilation to find all types annotated with@Annotation
. When I build it from themodule1
level it all works fine. The problem appears when I build it frommaster
level. Then, what happens is I get an exception that class B cannot be found.Here's how I find the types annotated with
@Annotation
:What happens is that the classloader will find also the following url:
and then it will be given to
Reflections
(methodscan
on line 235 inReflections
class ) where it will be treated as aSystemDir
so reflections will recursively go thorough all the subfolders and add all the classes it finds (which also includesmodule2/target/classes/ClassB.class
). Then it will try to load it and it will produce the error I pasted above. Now i'm not sure who's passing the master folder to the classpath, but I checked the maven classpath and I'm 100% sure it is not coming from maven. I also tried to add afilterInputsBy
with aFilterBuilder.Exclude
but that only allows me to filter on incoming files, and not the master folder (plus I have a project with more than 50 modules so I can't really exclude all the classes).Also in my case I have a project with more than 50 modules, so
reflections
will be really slow if it scans the master folder. I think the proper solution is not the scan the master folder at all.The text was updated successfully, but these errors were encountered: