ripsta
ripsta

Reputation: 1

Finding dead code in production environment using code coverage tool

I'm working on a huge monolith Java application with over 15000 lines of code that has been developed for quite a while now. My task is to find dead code (code that is never used) in the application. My idea was to approach this with JaCoCo code coverage tool being used in our production environment.

I've done some reading, but since JaCoCo (as most code coverage tools) are designed to show test coverage, there is not much information regarding my use case.

In the project, I use Gradle, which is a bit unfortunate, as I found out that for example for Maven, the JaCoCo plug-in provides a prepare agent task. There is no such thing for Gradle, so I'm wondering how I could set up the JaCoCo agent to receive the requests in production and mark the code that is being used. (I'm referring to code that is reachable in some flows but perhaps was never really used.)

I've found and example command that could be used:

java -javaagent:<path-to-application>/src/main/resources/lib/jacocoagent.jar=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver -jar <path-to-application>/target/myapplication.jar

Could someone explain what this command basically does? Could it be useful for my scenario? I'm open to any suggestions.

Upvotes: 0

Views: 49

Answers (0)

Related Questions