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
Duplicate resources found with Maven / Surefire patching test resources into the module path. #704
Comments
Hey @michael-simons, I'm sorry it took me so long to get to this bug. Can you please attach some verbose logs here? I don't know where the duplicate paths are coming from. I have no idea how module patching works. Does it effectively insert another module into the same module layer, with the patched files? If so, then yes, there are potentially two modules with the same files in them, so ClassGraph would already be doing the right thing, since |
I just hit this while trying to modularize https://github.com/webjars/webjars-locator-core The test webjars are being patched in and then reported as resources. In this case however, the duplicates aren't real duplicates since the My maven target directory looks like this |
From what I can tell,
This made me wonder, it looks like Intellij and maven are patching the main module, but also adding test-classes to the classpath. In that case, I would expect in both cases the path to be In this case it's buggy tho because it doesn't choose the correct full path for the patched module, it uses the main |
I had to guess a lot of things about how classfile visibility worked within modules, because it's so complex and was very poorly documented at the time I wrote module support into ClassGraph. So it's highly probable that there are behavioral mismatches between ClassGraph and whatever the JVM does. I'm swamped right now trying to get a company off the ground, so I won't have a lot of time to look into this. Any help you can give to track down what's going on would be appreciated. Thanks! |
I've got what I think is a fix. Instead of constructing a URI like we do for classpath resources, we instead use the module reader (+ a bit of reflection) to call the I've opened a pr here #793 |
The PR looks great to me, but @Sineaggi left a comment that there might be a better fix, so I'll wait on further work on this. Thanks! |
@Sineaggi any updates? |
@lukehutch sorry, I've not come back to this code in a while. As it stands, I'm not sure that all of classgraph is fixed with this change. However, it's more correct with the change in #793, and I'm not sure it's possible to patch |
I merged #793, since it looks like the right thing to do. @michael-simons please comment back here if this doesn't solve the problem. |
@michael-simons I tried running your
Any ideas? |
I'll reopen this since I can't reproduce the original issue, so I can't verify that this is fixed on my end. |
Find a simple reproducer attached (mpcg.zip): Maven / IntelliJ and friends will patch test classes and test resources into the main module when there's a
module-info.java
in the project (--patch-module mpcg=/Users/msimons/Projects/misc/mpcg/target/test-classes -
).When this happens, classgraph will discover resources multiple times.
I don't repeat the code from the reproducer here,
In this scenario,
will give me
whatever.cypher
twiceThis can be fixed by
but this is maybe not desired to skip the module path completely.
I am unsure if its an Maven issue or Classpath issue, though.
cc @sbrannen you expressed interest in this on twitter.
The text was updated successfully, but these errors were encountered: