Extensions > API reference > JavaInfo

JavaInfo

A provider encapsulating information about Java and Java-like targets.

JavaInfo

JavaInfo JavaInfo(output_jar, compile_jar, source_jar=None, compile_jdeps=None, generated_class_jar=None, generated_source_jar=None, native_headers_jar=None, manifest_proto=None, neverlink=False, deps=[], runtime_deps=[], exports=[], exported_plugins=[], jdeps=None, native_libraries=[])

The JavaInfo constructor.

Parameters

Parameter Description
output_jar required
The jar that was created as a result of a compilation (e.g. javac, scalac, etc).
compile_jar File; or None; required
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. There are a couple of special cases when this parameter may be set to None, for example adding a jar with resources or when used in a terminal rule like java_binary.
source_jar File; or None; default = None
The source jar that was used to create the output jar. Use pack_sources to produce this source jar.
compile_jdeps File; or None; default = None
jdeps information about compile time dependencies to be consumed by JavaCompileAction. This should be a binary proto encoded using the deps.proto protobuf included with Bazel. If available this file is typically produced by a header compiler.
generated_class_jar File; or None; default = None
A jar file containing class files compiled from sources generated during annotation processing.
generated_source_jar File; or None; default = None
The source jar that was created as a result of annotation processing.
native_headers_jar File; or None; default = None
A jar containing CC header files supporting native method implementation (typically output of javac -h).
manifest_proto File; or None; default = None
Manifest information for the rule output (if available). This should be a binary proto encoded using the manifest.proto protobuf included with Bazel. IDEs and other tools can use this information for more efficient processing.
default = False
If true only use this library for compilation and not at runtime.
deps sequence of JavaInfos; default = []
Compile time dependencies that were used to create the output jar.
runtime_deps sequence of JavaInfos; default = []
Runtime dependencies that are needed for this library.
exports sequence of JavaInfos; default = []
Libraries to make available for users of this library. See also java_library.exports.
exported_plugins sequence of JavaPluginInfos; default = []
A list of exported plugins. Optional.
jdeps File; or None; default = None
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.
native_libraries sequence of CcInfos; default = []
CC native library dependencies that are needed for this library.

annotation_processing

java_annotation_processing JavaInfo.annotation_processing

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

api_generating_plugins

JavaPluginData JavaInfo.api_generating_plugins

Returns data about API generating plugins.

Those annotation processors are applied to a Java target before producing its header jars (which contain method signatures). When no API plugins are present, header jars are generated from the sources, reducing critical path.

The api_generating_plugins is a subset of plugins.

compilation_info

java_compilation_info JavaInfo.compilation_info

Returns compilation information for this Java/Java-like target. May return None.

compile_jars

depset JavaInfo.compile_jars

Returns the Jars required by this target directly at compile time. They can be interface jars (ijar or hjar), regular jars or both, depending on whether rule implementations chose to create interface jars or not.

full_compile_jars

depset JavaInfo.full_compile_jars

Returns the regular, full compile time Jars required by this target directly. They can be

Note: JavaInfo.compile_jars can return a mix of interface Jars and regular Jars.

Only use this method if interface Jars don't work with your rule set(s) (e.g. some Scala targets) If you're working with Java-only targets it's preferable to use interface Jars via JavaInfo.compile_jars

java_outputs

list JavaInfo.java_outputs

Returns information about outputs of this Java/Java-like target.

outputs

java_output_jars JavaInfo.outputs

Returns information about outputs of this Java/Java-like target. Deprecated: use java_outputs. May return None.

plugins

JavaPluginData JavaInfo.plugins

Returns data about all plugins.

runtime_output_jars

sequence JavaInfo.runtime_output_jars

Returns a list of runtime Jars created by this Java/Java-like target.

source_jars

sequence JavaInfo.source_jars

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

to_json

string JavaInfo.to_json()

Deprecated. This API is deprecated and will be removed soon. Please do not depend on it. It is disabled with ---incompatible_struct_has_no_methods. Use this flag to verify your code is compatible with its imminent removal.
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"}}}
.

Deprecated: instead, use json.encode(x) or json.encode_indent(x), which work for values other than structs and do not pollute the struct field namespace.

to_proto

string JavaInfo.to_proto()

Deprecated. This API is deprecated and will be removed soon. Please do not depend on it. It is disabled with ---incompatible_struct_has_no_methods. Use this flag to verify your code is compatible with its imminent removal.
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
# }

Deprecated: use proto.encode_text(x) instead.

transitive_compile_time_jars

depset JavaInfo.transitive_compile_time_jars

Returns the transitive set of Jars required to build the target. Returns the same as JavaInfo.transitive_deps for legacy reasons.

transitive_deps

depset JavaInfo.transitive_deps

Returns the transitive set of Jars required to build the target. Returns the same as JavaInfo.transitive_compile_time_jars for legacy reasons.

transitive_native_libraries

depset JavaInfo.transitive_native_libraries

Returns the transitive set of CC native libraries required by the target.

transitive_runtime_deps

depset JavaInfo.transitive_runtime_deps

Returns the transitive set of Jars required on the target's runtime classpath. Returns the same as JavaInfo.transitive_runtime_jars for legacy reasons.

transitive_runtime_jars

depset JavaInfo.transitive_runtime_jars

Returns a transitive set of Jars required on the target's runtime classpath. Returns the same as JavaInfo.transitive_runtime_deps for legacy reasons.

transitive_source_jars

depset JavaInfo.transitive_source_jars

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