Using fast-classpath-scanner in Maven plugin
See original GitHub issueI am developing Maven plugin (typescript-generator) which is processing classes using reflection and I am using fast-classpath-scanner to get list of class names. It works well but now there is some issue when multi-module Maven project is built in parallel (reported here https://github.com/vojtechhabarta/typescript-generator/issues/142). In this case we get some class name from fast-classpath-scanner which we are not able to load using context class loader.
What I am doing now is:
- get “CompileClasspath” of the current Maven module
- create class loader
classLoader = new URLClassLoader(CompileClasspath, Thread.currentThread().getContextClassLoader())
- set it as context classloader
Thread.currentThread().setContextClassLoader(classLoader)
- get list of class names
new FastClasspathScanner().scan().getNamesOfClassesWithAnnotation()
- and then I use
Thread.currentThread().getContextClassLoader().loadClass()
which sometimes fails
I really don’t know what Maven is doing with classloaders especially in parallel builds but problematic class is from another module which is not in transitive dependencies of current module.
Should I use FastClasspathScanner.overrideClassLoaders()
and pass it my context classloader?
It seams that my context classloader has “correct” list of classes so probably using FastClasspathScanner.findBestClassLoader()
or letting fast-classpath-scanner to load classes is not right solution.
What do you think?
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (11 by maintainers)
Top GitHub Comments
Oh, a recent user-submitted change to the Maven setup must have broken the Maven release plug in (it has happened before – it’s quite brittle). I’ll see what I can do to fix that, although I don’t have a lot of Maven expertise!
@vojtechhabarta I’m going to close this, since I think the issue is solved; please open another bug if you still see issues.