Skip to main content

java_binary

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_apple_platforms: dict[str, str] = ...,
_build_only_native_code: bool = ...,
_exec_os_type: str = ...,
_is_building_android_binary: bool = ...,
_java_toolchain: str = ...,
base_dep: None | str = ...,
blocklist: list[str] = ...,
build_manifest: None | str = ...,
concat_deps: bool = ...,
contacts: list[str] = ...,
default_cxx_platform: None | str = ...,
default_host_platform: None | str = ...,
deps: list[str] = ...,
do_not_create_inner_jar: bool = ...,
generate_wrapper: bool = ...,
incremental_target_prefix: None | str = ...,
java_args_for_run_info: list[str] = ...,
java_runtime: None | str = ...,
java_version: None | str = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
main_class: None | str = ...,
manifest_file: None | str = ...,
meta_inf_directory: None | str = ...,
proguard_config: None | str = ...,
proguard_jvm_args: list[str] = ...,
proguard_library_jars: list[str] = ...,
) -> None

A java_binary() rule is used to create a JAR file of the compiled .class files and resources of the java_library() rules on which it depends.

Parameters

  • name: name of the target

  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: a list of visibility patterns restricting what targets can depend on this one

  • within_view: a list of visibility patterns restricting what this target can depend on

  • metadata: a key-value map of metadata associated with this target

  • tests: a list of targets that provide tests for this one

  • modifiers: an array of modifiers associated with this target

  • base_dep: Rule (normally of type java_library) that should be compiled and used as a base JAR to receive all dependencies through an append operation.

  • blocklist: A list of patterns that identify files to exclude from the final generated JAR file. Example:


    java_binary(
    name = 'example',
    blocklist = [
    # Excludes com.example.A and com.example.Alligator,
    # as well as their inner classes and any non-class files that happen to match
    # the pattern
    'com.example.A',

    # Excludes all files from org/slf4j/**/*.
    'org.slf4j',
    ],
    deps = [
    ':example1',
    ':third-party-stuff',
    ],
    )

  • build_manifest: MANIFEST containing stamped build attributes, that should be merged into the main jar manifest

  • concat_deps: Use zip concatenation instead of repacking all dependency jars, which is faster

  • deps: Rules (normally of type java_library) that should be compiled and whose .class files and resources should be included in the generated JAR file.

  • java_runtime: Expected java version used at runtime

  • java_version: Expected java version used at compile time

  • main_class: If provided, this will be the value specified as the Main-Class attribute of the META-INF/MANIFEST.MF file in the generated JAR file. Also, when this rule is used as an executable in a genrule(), main_class will indicate the class whose main() method will be invoked to process the command-line arguments. This is consistent with the expected usage of java -jar *<name.jar>* *<args>*.

  • manifest_file: If provided, this manifest will be used when generating the JAR file. If combined with main_class, the specified manifest file will be used but the main_class will override the main class in the manifest.