Policeman's Forbidden API Checker (3.10)

Allows to parse Java byte code to find invocations of method/class/field signatures and fail build (Apache Ant, Apache Maven, Gradle, or CLI)

Full name: de.thetaphi:forbiddenapis:3.10

Apache Ant

Task Documentation

Apache Maven: Mojo Goals

The minimum required version of Apache Maven is 3.1.0 (since forbiddenapis v3.6); previous versions also run with Maven 2.x.

Gradle

Task Documentation (Javadocs)

Command Line Interface

The JAR file can be called as command line tool using java -jar. This is the documentation of the CLI executable as printed by itsself:

$ java -jar forbiddenapis-3.10.jar --help
usage: java -jar forbiddenapis-3.10.jar [options]
Scans a set of class files for forbidden API usage.
    --allowmissingclasses                     don't fail if a referenced
                                              class is missing on
                                              classpath
    --allowunresolvablesignatures             DEPRECATED: don't fail if a
                                              signature is not resolving
 -b,--bundledsignatures <name>                name of a bundled signatures
                                              definition (separated by
                                              commas or option can be
                                              given multiple times)
 -c,--classpath <path>                        class search path of
                                              directories and zip/jar
                                              files
 -d,--dir <directory>                         directory (or jar file) with
                                              class files to check for
                                              forbidden api usage; this
                                              directory is also added to
                                              classpath
    --debug                                   enable debug logging
                                              (stderr)
 -e,--excludes <pattern>                      ANT-style pattern to exclude
                                              some files from checks
                                              (separated by commas or
                                              option can be given multiple
                                              times)
 -f,--signaturesfile <file>                   path to a file containing
                                              signatures (option can be
                                              given multiple times)
 -h,--help                                    print this help
 -i,--includes <pattern>                      ANT-style pattern to select
                                              class files (separated by
                                              commas or option can be
                                              given multiple times,
                                              defaults to '**/*.class')
    --ignoresignaturesofmissingclasses        if a class is missing while
                                              parsing signatures files,
                                              all methods and fields from
                                              this class are silently
                                              ignored
    --signatureswithseveritysuppress <name>   forbidden API signature for
                                              which violations should not
                                              be reported at all
                                              (separated by commas or
                                              option can be given multiple
                                              times)
    --signatureswithseveritywarn <name>       forbidden API signature for
                                              which violations just be
                                              reported at warn level but
                                              not lead to a non-success
                                              exit code (separated by
                                              commas or option can be
                                              given multiple times)
    --suppressannotation <classname>          class name or glob pattern
                                              of annotation that
                                              suppresses error reporting
                                              in classes/methods/fields
                                              (separated by commas or
                                              option can be given multiple
                                              times)
 -V,--version                                 print product version and
                                              exit
Exit codes: 0 = SUCCESS, 1 = forbidden API detected, 2 = invalid command
line, 3 = unsupported JDK version, 4 = other error (I/O,...)

Additional documentation