Buck: buck targets
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

buck targets

List information about the build targets in the current project.

buck targets <build target> | <build target pattern> ...

The buck targets command must take at least one parameter: a build target or build target pattern or a combination of these.

The following prints all build targets in the project (sorted alphabetically) to standard out:

buck targets //...

You can pass a list of targets to buck targets, and Buck prints information only for those targets. For example, the following command line prints the target main from the BUCK file in the root of the Buck project and all the targets from the BUCK file in the subdirectory myclass.

buck targets //:main //myclass:

The buck targets command is commonly used with the --show-output option to obtain the output paths for the build artifacts for Buck targets.

buck targets --show-output //java/com/myproject:binary
> //java/com/myproject:binary buck-out/gen/java/com/myproject/binary.apk


  • --type

    The types of target by which to filter. For example:

    buck targets //java/com/myproject/... --type java_test java_binary

    Note that the --type parameter comes after the specified targets.

    This parameter can be handy in programmatic tasks, such as running all of the Java tests under //java/com/myproject:

    buck targets //java/com/myproject/... --type java_test | xargs buck test

  • --referenced-file

    Filters targets by the list of rules that include the specified file in their transitive closure.

    For example, to run all tests that could be affected by a particular file, you could use:

    buck targets //java/com/myproject/... --type java_test \
      --referenced-file java/com/example/Foo.java |
      xargs buck test

  • --json

    Print a JSON representation of each target.

    In addition, the JSON includes a list of direct_dependencies for each target, which may include additional dependencies for targets whose descriptions implement ImplicitDepsInferringDescription. The fully qualified names of targets are given.

    For example, when resolving a genrule, the direct dependencies includes both the build targets in deps as well as any build targets in a script associated with the genrule.

  • --output-attributes

    Specify the attributes used in the JSON representation.

    If you omit this option, Buck shows all attributes.

  • --print0

    Delimit targets using the ASCII NUL character if --json is not specified. This facilitates use with xargs:

    buck targets --print0 | xargs -0 buck build

  • --resolve-alias

    Print the fully-qualified build target for the specified alias[es]. This command also accepts build targets. For more information, see [alias] in the .buckconfig documentation.

  • --show-output

    Print the relative paths to the output for each target after the target name. Note that some rules—such as genrule—generate sources instead of build artifacts.

  • --show-rulekey

    Print the rule keys, for the specified targets.

    For example, if you have a rule named main defined in the build file in your current directory, the following command prints its rule key.

    buck targets --show-rulekey ':main'

    Note that the rule key for a target is different from the target hash for that target. (See show-target-hash below.) Further, the inputs for the computation of the rule key are not a superset of the inputs for the target hash. For example, the value of the visibility argument is not an input for the rule key but is an input for the target hash.

  • --show-transitive-rulekeys

    When specified in conjunction with --show-rulekey, prints the rule keys for the specified targets and their transitive closure.

    For example, if you have a rule named main defined in the build file in your current directory, the following command prints the rule key for that rule and the rule keys for all of the rules that are in its transitive closure.

    buck targets --show-rulekey --show-transitive-rulekeys ':main'

  • --show-target-hash

    Print each rule's target hash after the rule's name. Target hashes can be used to detect which targets are affected when source files in BUCK files change: if a target is affected, its target hash will be different after the change from what it was before.

    A target hash is created by finding all the transitive dependencies of the given target and hashing all their attributes and the files they reference. For more details about how the referenced files are hashed see the --target-hash-file-mode flag. The format of the data that is hashed is undocumented and can change between Buck versions.

  • --target-hash-file-mode

    Modify how target hashes are computed.

    Can be set to either PATHS_AND_CONTENTS or PATHS_ONLY.

    If set to PATHS_AND_CONTENTS (the default), the contents of all files referenced from the targets will be used to compute the target hash.

    If set to PATHS_ONLY, only files' paths contribute to the hash. PATHS_ONLY will generally be faster because it does not need to read all of the referenced files, but it will not detect file changes automatically. See --target-hash-modified-paths for another way to handle changes to referenced files without losing the performance benefits.

  • --target-hash-modified-paths

    Modify how target hashes are computed.

    If a target or its dependencies reference a file from the specified set of paths, the target's hash will be different than if this option had been omitted. Otherwise, the target's hash will be the same as if this option was omitted.

    This option can be used to detect changes in referenced files if the list of modified files is available from an external source, such as a source control system.

    This option is effective only when --target-hash-file-mode is set to PATHS_ONLY. Otherwise, the actual contents of the files are used to detect modifications and this option is ignored.