Sometimes it’s useful to assert that the code in two jars is identical. Why? Maybe you’re working on an open source Java project, and you realize that the code has never been formatted. You run your favorite formatter and go to open a PR when you notice that you’ve changed thousands of lines. Nobody wants to approve that PR because they can’t be sure you aren’t trying to sneak in something malicious. However, with this tool you can assert the code in the jar before formatting is the same as the code in the jar after formatting.
With a proper go installation you can simply
go install github.com/sosodev/java-verifier. Otherwise you can download the binary for your system
from the releases tab.
- Disable compiler metadata by adding the
-g:noneflag when invoking
javac. You can do this with gradle by adding
options.compilerArgs << '-g:none'to the
JavaCompileblock in your
- Build the jar for the main branch and extract it somewhere (jars can be extracted as a normal zip file).
- Build the jar for the comparison branch and extract it somewhere.
- Execute the verifier like so
java-verifier <path-to-original-jar-directory> <path-to-comparison-jar-directory>