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="ea3ebc47cf1d3ebe0759d3319f31a928df7f24a5" # update this as needed jvm_classpath_validator_sha256="fee14b69faaefce808cf86aa627bc727c7be91b40bdeda04052b1d980a45df8d" # 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 include_prefixes = ["example_prefix"], #optional include_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 prefixes or suffix and look only at entries that match the provided
prefixes or suffixes (or all entries if the
include_prefix
andinclude_suffixes
are not provided) - 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
##ignore_ vs include_ parameters
The test will perform the filtering out of all entries from JARs before looking at what to include, i.e.
if an entry from a JAR matches both ignore_
and include_
pattern, then ignore_
will take precedence.
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.