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
RFE: Duplicate checker #256
Comments
|
also mentioned on https://stackoverflow.com/a/52637869/421602 |
|
Hi @vorburger, thanks for this suggestion and code submission! I can see how this would be useful, and it should probably be part of the
Note that ClassGraph already does a lot of work to ignore duplicates:
Please let me know if this works for you! |
|
@lukehutch nice! I'll switch to using that, once you cut a release including this. What this is missing is just the filtering of well-known harmless duplicates. Do you want PR with my ClasspathHellDuplicatesCheckRule (and that filtering) ? |
|
also, perhaps after we have the JUnit Rule along, it would be neat to highlight this on the README? |
|
@vorburger Unfortunately the list of "well-known" duplicates will never be complete, and it will be a neverending battle to keep it up to date as part of a library whose goal is to be as generic and general as ClassGraph strives to be. It's also conceivable that such a list could end up accidentally masking something that should be detected as a duplicate. I think this is better left up to users of ClassGraph to implement their own filters for their own specific classpaths / module path situations. However, feel free to create a mini-library that depends on ClassGraph and wraps your duplicate filters, and even potentially implements a minimal subset of the JHades API so that this can serve as a drop-in replacement for that. It seems like that may be useful, since JHades development has stalled. I have relased this as 4.2.7. Thanks again for the suggestion and for the code submission! |
Yes, I updated the API docs to reflect the new API calls, and I'm about to add an example in the "Code examples" page too, since this is a useful capability. |
|
see the ClasspathHellDuplicatesChecker in OpenDaylight's infrautils and a brief related write up in http://blog2.vorburger.ch/2019/02/how-to-find-duplicate-classes-and.html |
|
@vorburger this is great, but be aware of one thing: if the exact same path or URL (after canonicalization) is listed on the classpath or module path multiple times, the second and subsequent are ignored by ClassGraph (since that is more of less semantically what the JRE does too). Therefore, duplicates are only detected if the same resources are present in multiple different modules, jars or directories. Maintaining PS you should assign the ScanResult in a try-with-resources statement, so that proper cleanup does not depend upon a finalizer. |
Erm ... but that's perfectly fine, right? That's kind of the point of what I'm after - to find duplicate classes in different JARs, when you (or an external 3rd-party) made a mess of your dependencies. You can't really have a duplicate of the exact same class in the same single JAR.
I'm not planning to... 😈
Thanks for noticing and pointing it out - fixed in https://git.opendaylight.org/gerrit/#/c/80158. |
Yes, it's fine, I just wanted to make the distinction between multiple listings of the same jar on the classpath, and multiple occurrences of the same file within different classpath elements. The first cannot be detected (but may still be considered by somebody to be problematic), but the second can. |
* Update infrautils from branch 'master'
to 8c243550ae32685137755669daecf72cd2dbf5e2
- assign ScanResult in try-with-resources (ClasspathHellDuplicatesChecker)
classgraph/classgraph#256
http://blog2.vorburger.ch/2019/02/how-to-find-duplicate-classes-and.html
Change-Id: I6862260c72f285f9a7704f071ba8fff2a946a698
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
classgraph/classgraph#256 http://blog2.vorburger.ch/2019/02/how-to-find-duplicate-classes-and.html Change-Id: I6862260c72f285f9a7704f071ba8fff2a946a698 Signed-off-by: Michael Vorburger <vorburger@redhat.com>
I have used this library to implement a classpath duplicate checker. The gist of it is basically:
Basically I re-built something very similar to https://github.com/jhades/ (see http://jhades.github.io) or https://github.com/basepom/duplicate-finder-maven-plugin but using classgraph. (The motivation for this was that JHades could not support Java 9+.)
Filing this issue here to ask whether a contribution (PR) of utility class like my
ClasspathHellDuplicatesCheckerinto this lib would be of any interest. Alternative I could just add a link to it somewhere in the doc to make it easier and let people build something like it.Also absolutely no offense taken if this doesn't fit here - just close in that case, no worries.
The text was updated successfully, but these errors were encountered: