Extensions > API reference > JavaInfo

JavaInfo

Encapsulates all information provided by Java rules.

JavaInfo

JavaInfo JavaInfo(output_jar, compile_jar=None, source_jar=None, neverlink=False, deps=[], runtime_deps=[], exports=[], jdeps=None)

The JavaInfo constructor.

Parameters

Parameter Description
output_jar

File

The jar that was created as a result of a compilation (e.g. javac, scalac, etc).

compile_jar

File

A jar that is added as the compile-time dependency in lieu of output_jar. Typically this is the ijar produced by run_ijar. If you cannot use ijar, consider instead using the output of stamp_ijar. If you do not wish to use either, you can simply pass output_jar.

source_jar

File

The source jar that was used to create the output jar. Use pack_sources to produce this source jar.

bool

If true only use this library for compilation and not at runtime.

deps

sequence of JavaInfos

Compile time dependencies that were used to create the output jar.

runtime_deps

sequence of JavaInfos

Runtime dependencies that are needed for this library.

exports

sequence of JavaInfos

Libraries to make available for users of this library. See also java_library.exports.

jdeps

File

jdeps information for the rule output (if available). This should be a binary proto encoded using the deps.proto protobuf included with Bazel. If available this file is typically produced by a compiler. IDEs and other tools can use this information for more efficient processing.

annotation_processing

java_annotation_processing JavaInfo.annotation_processing

Returns information about annotation processing for this Java target. May return None.

compilation_info

java_compilation_info JavaInfo.compilation_info

Returns compilation information for this Java target. May return None.

compile_jars

depset JavaInfo.compile_jars

Returns the compile time jars required by this target directly. They can be:
  • interface jars (ijars), if an ijar tool was used
  • normal full jars, if no ijar action was requested
  • both ijars and normal full jars, if this provider was created by merging two or more providers created with different ijar requests

full_compile_jars

depset JavaInfo.full_compile_jars

Returns the full compile time jars required by this target directly. They can be
  • the corresponding normal full jars of the ijars returned by `compile_jars`
  • the normal full jars returned by `compile_jars`
Note: `compile_jars` can return a mix of ijars and normal full jars. In that case, `full_compile_jars` returns the corresponding full jars of the ijars and the remaining normal full jars in `compile_jars`.

outputs

java_output_jars JavaInfo.outputs

Returns information about outputs of this Java target. May return None.

runtime_output_jars

sequence JavaInfo.runtime_output_jars

Returns the runtime output jars provided by this Java target.

source_jars

sequence JavaInfo.source_jars

Returns a list of jar files containing all the uncompiled source files (including those generated by annotations) from the target itself, i.e. NOT including the sources of the transitive dependencies

to_json

string JavaInfo.to_json()

Creates a JSON string from the struct parameter. This method only works if all struct elements (recursively) are strings, ints, booleans, other structs, a list of these types or a dictionary with string keys and values of these types. Quotes and new lines in strings are escaped. Examples:
struct(key=123).to_json()
# {"key":123}

struct(key=True).to_json()
# {"key":true}

struct(key=[1, 2, 3]).to_json()
# {"key":[1,2,3]}

struct(key='text').to_json()
# {"key":"text"}

struct(key=struct(inner_key='text')).to_json()
# {"key":{"inner_key":"text"}}

struct(key=[struct(inner_key=1), struct(inner_key=2)]).to_json()
# {"key":[{"inner_key":1},{"inner_key":2}]}

struct(key=struct(inner_key=struct(inner_inner_key='text'))).to_json()
# {"key":{"inner_key":{"inner_inner_key":"text"}}}

to_proto

string JavaInfo.to_proto()

Creates a text message from the struct parameter. This method only works if all struct elements (recursively) are strings, ints, booleans, other structs or dicts or lists of these types. Quotes and new lines in strings are escaped. Struct keys are iterated in the sorted order. Examples:
struct(key=123).to_proto()
# key: 123

struct(key=True).to_proto()
# key: true

struct(key=[1, 2, 3]).to_proto()
# key: 1
# key: 2
# key: 3

struct(key='text').to_proto()
# key: "text"

struct(key=struct(inner_key='text')).to_proto()
# key {
#   inner_key: "text"
# }

struct(key=[struct(inner_key=1), struct(inner_key=2)]).to_proto()
# key {
#   inner_key: 1
# }
# key {
#   inner_key: 2
# }

struct(key=struct(inner_key=struct(inner_inner_key='text'))).to_proto()
# key {
#    inner_key {
#     inner_inner_key: "text"
#   }
# }

struct(foo={4: 3, 2: 1}).to_proto()
# foo: {
#   key: 4
#   value: 3
# }
# foo: {
#   key: 2
#   value: 1
# }

transitive_compile_time_jars

depset JavaInfo.transitive_compile_time_jars

Depset of compile time jars recursively required by this target. See `compile_jars` for more details.

transitive_deps

depset JavaInfo.transitive_deps

Returns the transitive set of Jars required to build the target.

transitive_exports

depset JavaInfo.transitive_exports

Returns transitive set of labels that are being exported from this rule.

transitive_runtime_deps

depset JavaInfo.transitive_runtime_deps

Returns the transitive set of Jars required on the target's runtime classpath.

transitive_runtime_jars

depset JavaInfo.transitive_runtime_jars

Depset of runtime jars required by this target

transitive_source_jars

depset JavaInfo.transitive_source_jars

Returns the Jars containing Java source files for the target and all of its transitive dependencies.