-
Notifications
You must be signed in to change notification settings - Fork 34
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
Report the current classpath when failing due to not finding a class on the classpath #202
Comments
I will check if I can provide the classpath. The problem is that the Forbiddenapis Checker class only uses a ClassLoader instance. If the ToString of it would be helpful it would be easiest to print it. |
ClassLoader#toString() does not print anything useful. The only chance to get this running is to pass a "human readable string representation" to the ForbiddenApis Checker class next to the classloader. The type of ClassLoader differs between Gradle, Maven and Ant so it is up to their internals how the classloader is built. I don't have access to the original classpath in all cases. |
Most of those are probably instances of URLClassLoader though, Uwe. It's a cheap shot to try instanceof and then https://docs.oracle.com/javase/7/docs/api/java/net/URLClassLoader.html#getURLs() (I've done it in the past). |
Another cheap-shot alternative is to try to getResource on MANIFEST.MF and enumerate everything possible, listing URLs. I also did this in the past (blush) - this works with non-url classloaders most of the time too. |
Actually I have access to some path representation in some build system specific way (Path in Ant, Strings of files in Maven and the CLI, a List of File instances in Gradle). I just need to pass an additional string for human consumption to the Checker instance. |
…bugging od classpath/JDK related problems. This closes #202
I am not fully happy with it, but I added a PR #206. This also adds DEBUG as log level. If you have classpath issues you can enable debug logging and it will report more detailed information to JDK type and also the classpath used. I will maybe rework the PR and remove the classpath logging from the Checker and just always report classpath when task starts (separately for each build system). So see it as preview. |
I changed the PR to always report classpath using DEBUG logging on task startup in Maven, Gradle, Ant |
Now looks like this if you run gradle with
|
We have a series of bizarre build failures where forbidden-apis failed because it couldn't find
org.apache.commons.lang3.StringUtils
.Our problem is - we only add the commons-lang3 signatures files to the list, if the task's classpath includes the commons-lang3 jar.
So somehow it seems that:
task.classpath
and iterate through the classpath, it says commons-lang3 is there. BUT:To figure out which of these is the case, it would be nice if the error message included the classpath it was using for this search. The same build failure doesn't happen when I run the same build locally - it passes!
(As far as investigating the underlying issue, I'm trying an update from v3.1 to v3.3 to see if it magically fixes it.)
The text was updated successfully, but these errors were encountered: