java_binary
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.
Function Signature
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
Parameters
-
name
: (required)name of the target
-
default_target_platform
: (defaults to:None
)specifies the default target platform, used when no platforms are specified on the command line
-
target_compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
exec_compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
-
visibility
: (defaults to:[]
)a list of visibility patterns restricting what targets can depend on this one
-
within_view
: (defaults to:["PUBLIC"]
)a list of visibility patterns restricting what this target can depend on
-
metadata
: (defaults to:{}
)a key-value map of metadata associated with this target
-
tests
: (defaults to:[]
)a list of targets that provide tests for this one
-
modifiers
: (defaults to:[]
)an array of modifiers associated with this target
-
base_dep
: (defaults to:None
)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
: (defaults to:[]
)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
: (defaults to:None
)MANIFEST containing stamped build attributes, that should be merged into the main jar manifest
-
concat_deps
: (defaults to:False
)Use zip concatenation instead of repacking all dependency jars, which is faster
-
deps
: (defaults to:[]
)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
: (defaults to:None
)Expected java version used at runtime
-
java_version
: (defaults to:None
)Expected java version used at compile time
-
main_class
: (defaults to:None
)If provided, this will be the value specified as the
Main-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
: (defaults to:None
)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 themain_class
will override the main class in the manifest.