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 typejava_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 typejava_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 theMain-Class
attribute of theMETA-INF/MANIFEST.MF
file in the generated JAR file. Also, when this rule is used as an executable in agenrule()
,main_class
will indicate the class whosemain()
method will be invoked to process the command-line arguments. This is consistent with the expected usage ofjava -jar *<name.jar>* *<args>*
. -
manifest_file
: If provided, this manifest will be used when generating the JAR file. If combined withmain_class
, the specified manifest file will be used but themain_class
will override the main class in the manifest.