Buck: java_binary()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

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.

Arguments

  • name (required) #

    The short name for this build target. Also, the name of the generated JAR file.

  • 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.

  • main_class (defaults to None) #

    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 (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 the main_class will override the main class in the manifest.

  • meta_inf_directory (defaults to None) #

    Note: This has beta support currently. If provided, the contents in this directory will end up in the META-INF directory inside the generated JAR file.

  • blacklist (defaults to []) #

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

    java_binary(
      name = 'example',
      blacklist = [
        # 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',
      ],
    )
    

  • tests (defaults to []) #

    List of build targets that identify tests that exercise this target.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().