Identify unused banks by code coverage?

I have a project with a million cans (well, a lot). They came to me maven, and I use only a small set of functions. For cleanliness, I was wondering, with jars I could get along.

My first thought was to run the program using the code coverage tool, and then find the classes that were affected.

Has anyone done this before? Or are there smarter tricks to achieve the same?

+6
source share
3 answers

You can start a project using the -verbose:class VM option. This will print for all loaded classes from which they are loaded. Using some smart parsing app / grep / regexp will allow you to filter jar names into a set of unique records and tell you which ones are used.

I think that would be easier, because it will automatically tell you if the class is used and if so, in which bank.

Of course, the problem with this and the scope of the code is that you can delete the jar, which is used only in some exceptional cases, but your compiler will complain if you deleted one or two too many, leaving you with (mostly not too complicated ) the task is to find which jar class is in.

Possible suggestion when using linux:

java -verbose:class <your startup command here> | grep "\[Loaded" | grep -o "from .*\]" | cut -c 6- | sort | uniq

If you are not using linux, then save the file, get a Linux machine and run it on linux (or use something to run bash commands on windows)

+4
source

Consider using an existing tool, such as Finder Finder or JDepend .

As with all static analysis tools, the use of reflective or DI structures may discard this; I resorted to user tools that use this and other inputs to figure them out, although it is still static.

For complete usage information at runtime, you can use the Thirler solution, although whether it is completed may depend on which code paths are executed.

0
source

You can use the Maven Dependency Plugin to analyze the dependency tree. He will also offer you dependencies that are loaded / added to your project, because they depend on other banks.

Run mvn dependency:tree and see if you are using several unnecessary jars.

0
source

Source: https://habr.com/ru/post/901213/


All Articles