Skip to content

martynasp-wix/jvm-classpath-validator

 
 

Repository files navigation

Bazel classpath_collision_test Build Status

Overview

Test and report tool to validate classpath collision cases

Getting started

  1. 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
    )
  2. 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
    )
  3. Run bazel test //path/to/package:test_classpath

How does the test work?

  • 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.

Example for failure report

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

Default ignore list

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.

About

Bazel test rule that checks for JVM classpath collisions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 78.2%
  • Starlark 21.8%