Test and report tool to validate classpath collision cases
- Add to your WORKSPACE file the following:
# WORKSPACE file load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") jvm_classpath_validator_version="fd8bd402e43396cc726d222a3f4bbb6f0f103f91" # update this as needed jvm_classpath_validator_sha256="bead7f1841837270d8218233e638dd56eecc98e4354b7cdf52d0e15a23e7c425" # update this as needed http_archive( name = "jvm_classpath_validator", url = "https://github.com/or-shachar/jvm-classpath-validator/archive/%s.tar.gz" % jvm_classpath_validator_version, strip_prefix = "jvm-classpath-validator-%s" % jvm_classpath_validator_version, sha256 = jvm_classpath_validator_sha256 )
- Add a test in one of the build files:
# BUILD.bazel file load("@jvm_classpath_validator//:classpath_validator.bzl", "classpath_collision_test") java_binary( name = "foo", runtime_deps = [...] ) classpath_collision_test( name = "test_classpath", target = "foo", ignore_prefixes = ["example_prefix"], #optional ignore_suffixes = ["example_suffix"], #optional )
- Run
bazel test //path/to/package:test_classpath
- The test would inspect the different jar entries of any jar in runtime closure of given
target
- The test would ignore entries with given suffix or prefixes.
- If same entry was found in two places with different content (digest based) the test would fail and a report would be emitted.
Classpath Collision Finder
====================
[INFO] Looking for collisions in 3 jar files
=======
Found 1 collisions
[//example/a/com/example/duppy:duppy <> //example/b/com/example/duppy:duppy]:
com/example/duppy/Duppy.class
I allowed myself to add few default prefixes / suffixes to ignore. You can find them here. If you feel like the defaults should change - please kindly open an issue.