java_binary
java_binary
def java_binary(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_build_only_native_code: bool = select({"prelude//android/constraints:build_only_native_code": True, "DEFAULT": False}),
_exec_os_type: str = "prelude//os_lookup/targets:os_lookup",
_is_building_android_binary: bool = select({"prelude//os:building_android_binary": True, "DEFAULT": False}),
_java_toolchain: str = "gh_facebook_buck2_shims_meta//:java",
base_dep: None | str = None,
blocklist: list[str] = [],
build_manifest: None | str = None,
concat_deps: bool = False,
contacts: list[str] = [],
default_cxx_platform: None | str = None,
default_host_platform: None | str = None,
deps: list[str] = [],
do_not_create_inner_jar: bool = False,
generate_wrapper: bool = False,
incremental_target_prefix: None | str = None,
java_args_for_run_info: list[str] = [],
java_runtime: None | str = None,
java_version: None | str = None,
labels: list[str] = [],
licenses: list[str] = [],
main_class: None | str = None,
manifest_file: None | str = None,
meta_inf_directory: None | str = None,
proguard_config: None | str = None,
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.