Does anyone know of a Gradle plugin that can stati...
# community-support
l
Does anyone know of a Gradle plugin that can statically analyze
runtimeClasspath
to find possible linkage errors (eg:
NoClassDefFoundError
,
NoSuchFieldError
,
NoSuchMethodError
)? What I want to be able to do is give it a set of entry points (eg:
com.example.MyApp.main(String[])
) and optionally an allowlist of methods, fields, and classes that are "ok to be missing", and it'd crawl the classpath starting at those entry points, reporting all references to things that can't be found, and aren't in the allowed-missing list.
e
https://r8.googlesource.com/r8 will report that as it (tries to) minify
l
That's an interesting idea, thanks!
I was able to get this to mostly work using the gr8 plugin. A few notes/caveats: • It's kind of slow. I suspect that this is because it isn't just scanning for problems. but also constructing jars that I don't really need. • It doesn't error if the very thing I've asked it to "keep" is missing, which seems like an odd choice. Instead, it just prints out an "info" message but still completes with "build succeeded". So the only errors it catches are if something I'm keeping is present, but it depends on something else that's missing. • Shrinking has to be enabled, but I had to turn off optimization. This is fine, as I don't intend on using its output jar anyway, but I don't really understand the error it's giving me when optimization is enabled: "Unused argument with users"
e
1. yeah probably r8 does way more than you need so it's slow. I don't know of anything else preexisting 2. in the future https://r8.googlesource.com/r8/+/master/doc/keepanno-guide.md annotations should be able to replace keep rules, which avoids "keep"ing something that doesn't exist 3. I don't know why… sounds like you don't need optimization or obfuscation so that shouldn't be an issue
l
For #2, being able to use an annotation would be convenient, but the bigger issue is the fact that r8 doesn't treat it as an error when something marked "keep" is missing.
Searching around, I found some mentions that "Animal Sniffer" can apparently be used to do this, but it's unclear to me how. There are also apparently at least two tools for doing this with maven: Spotify's Missing Link and supposedly the enforcer plugin can do some kind of linkage check.