Class and resources discovering and loading during build / augmentation time change in 2.7 #23312
Replies: 10 comments 11 replies
-
Please, don't use the ClassGraph API in Quarkus. It's based on assumptions about internal implementation of the QuarkusClassLoader and may break any time, which is what happened in your case. |
Beta Was this translation helpful? Give feedback.
-
Hmm… That's not helpful. a) I tried passing
Thanks. |
Beta Was this translation helpful? Give feedback.
-
What do you mean by ignoring parent class loader though? |
Beta Was this translation helpful? Give feedback.
-
As I mentioned previously, you should be able to load classpath resources using |
Beta Was this translation helpful? Give feedback.
-
During augmentation there is a classloader hierarchy and you should not filter out parent classloaders. |
Beta Was this translation helpful? Give feedback.
-
Sorry, then they should keep up with the changes in Quarkus. |
Beta Was this translation helpful? Give feedback.
-
You could also look into Jandex. This is what Quarkus uses internally to scan classpath. |
Beta Was this translation helpful? Give feedback.
-
@aloubyansky would it be possible to provide a SPI to Classgraph that they could use? Because it's a pretty popular library and they made the effort to support Quarkus, even if it's with a hack, so IMHO we should be nice to them if we can. |
Beta Was this translation helpful? Give feedback.
-
FYI classgraph/classgraph#642 instead of wasting energy debating here. @gsmet it would be helpful to have your input here. ClassGraph is an important tool, and it isn't broken. As a matter of fact, it has been working with Quarkus just fine since 2020. Also, it's approach is not hacky, it's just not using dependencies to get access to the elements. I would see it as a compliment that someone contributed the handler to make it work on Quarkus (as it already does on Boot and a broad range of other containers). From my perspective, an SPI somewhere on that level of that element interface would be helpful. Or at least some guarantees. |
Beta Was this translation helpful? Give feedback.
-
Apologies for the delay in responding to this, since I have been traveling... @michael-simons contributed a fix for the Quarkus classloader changes to ClassGraph, and those fixes were merged and released as ClassGraph version 4.8.139. As far as whether ClassGraph's approach is hacky: well, if a classloader does not expose its classpath through a supported public API, then there is literally no way of getting the classpath other than via reflection of non-public methods and fields. Of course reflection will fail eventually because of strong encapsulation, in fact reflection into the Quarkus classloader probably already fails today on JDK 16+, so you really need to work with the Quarkus creators to have them define a supported public API for getting the classpath. For the record, I built a workaround to the encapsulation issue, called Narcissus, and this can be used as a stop-gap in the meanwhile until the classloader is fixed (Narcissus will be used automatically by ClassGraph, if it is present on the classpath, and if the platform is supported). |
Beta Was this translation helpful? Give feedback.
-
Hi there.
I'm sorry for the noise, but I'm directly paging @lukehutch and @aloubyansky here (the latter is hopefully the correct one, @gsmet ;) )
I maintain Neo4j-Migrations: https://github.com/michael-simons/neo4j-migrations
Which let's you execute Cypher scripts (resources) and Java classes against Neo4j.
I use ClassGraph to discover those resources.
Since last release I do support Quarkus in native mode. To make this possible, I moved all discovering of things into build time / augmentation. That works well with Quarkus 2.6.x (all releases).
Those classes:
https://github.com/michael-simons/neo4j-migrations/blob/0db309476f9c737b1b4674193f838f7e3c74ec75/neo4j-migrations-quarkus-parent/runtime/src/main/java/ac/simons/neo4j/migrations/quarkus/runtime/StaticClasspathResourceScanner.java#L57-L70
and
https://github.com/michael-simons/neo4j-migrations/blob/0db309476f9c737b1b4674193f838f7e3c74ec75/neo4j-migrations-quarkus-parent/runtime/src/main/java/ac/simons/neo4j/migrations/quarkus/runtime/StaticJavaBasedMigrationDiscoverer.java#L48-L61
are invoked from a build time processor, both in 2 steps (creating the scanner, than executing them and adding things to the augmented classes), like this:
https://github.com/michael-simons/neo4j-migrations/blob/0db309476f9c737b1b4674193f838f7e3c74ec75/neo4j-migrations-quarkus-parent/deployment/src/main/java/ac/simons/neo4j/migrations/quarkus/deployment/MigrationsProcessor.java#L58-L83
With Quarkus 2.7.x this suddenly fails: https://github.com/michael-simons/neo4j-migrations/runs/5002711436?check_suite_focus=true#step:9:1522 no resources are found anymore.
What fails exactly is
and the counterpart for Java classes.
It doesn't work when I use the current thread class loader either.
It works during runtime, but this is not what I want.
So, I'm unsure where to open an issue: In ClassGraph or in Quarkus.
I have tendency towards Quarkus though, as ClassGraph hasn't change, but Quarkus seems to have.
The thing is reproducible with the above project in this branch https://github.com/michael-simons/neo4j-migrations/tree/dependabot/maven%2Fquarkus.version-2.7.0.Final
when building like this:
(Requires JDK 17).
Any pointers would be much appreciated, I'd like to celebrate Quarkus 2.7 with you :)
Beta Was this translation helpful? Give feedback.
All reactions