atteo / classindex

Index classes, do not scan them!
Apache License 2.0
263 stars 43 forks source link

Update documentation with modular @IndexSubclasses gotcha #68

Open pentlander opened 3 years ago

pentlander commented 3 years ago

When your project uses a module-info.java class, using @IndexSubclasses on the package-info.java class does not work out of the box. According to the javadoc:

Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

This means that the user needs to add opens package.containing.package.info to the module-info.java in order for the ClassIndex.getPackageClasses function to work. I ran into this problem myself, so I thought it would be useful to document for others.