java_common
Utilities for Java compilation support in Starlark.Members
add_compile_time_jdeps
JavaInfo java_common.add_compile_time_jdeps(java_info, *, compile_time_jdeps=[])Experimental. This API is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting
--experimental_google_legacy_api
Returns a copy of the given JavaInfo with the given compile-time jdeps files added.
Parameters
Parameter | Description |
---|---|
java_info
|
The JavaInfo to clone. |
compile_time_jdeps
|
Compile-time jdeps files to add. |
add_constraints
JavaInfo java_common.add_constraints(java_info, *, constraints=[])Experimental. This API is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting
--experimental_google_legacy_api
Returns a copy of the given JavaInfo with the given constraints added.
Parameters
Parameter | Description |
---|---|
java_info
|
The JavaInfo to enhance. |
constraints
|
Constraints to add |
compile
JavaInfo java_common.compile(ctx, *, source_jars=[], source_files=[], output, output_source_jar=None, javac_opts=[], deps=[], exports=[], plugins=[], exported_plugins=[], annotation_processor_additional_inputs=[], annotation_processor_additional_outputs=[], strict_deps='ERROR', java_toolchain, host_javabase, sourcepath=[], resources=[], neverlink=False)Compiles Java source files/jars from the implementation of a Starlark rule and returns a provider that represents the results of the compilation and can be added to the set of providers emitted by this rule.
Parameters
Parameter | Description |
---|---|
ctx
|
The rule context. |
source_jars
|
A list of the jars to be compiled. At least one of source_jars or source_files should be specified. |
source_files
|
A list of the Java source files to be compiled. At least one of source_jars or source_files should be specified. |
output
|
|
output_source_jar
|
The output source jar. Optional. Defaults to `{output_jar}-src.jar` if unset. |
javac_opts
|
A list of the desired javac options. Optional. |
deps
|
A list of dependencies. Optional. |
exports
|
A list of exports. Optional. |
plugins
|
A list of plugins. Optional. |
exported_plugins
|
A list of exported plugins. Optional. |
annotation_processor_additional_inputs
|
A list of inputs that the Java compilation action will take in addition to the Java sources for annotation processing. |
annotation_processor_additional_outputs
|
A list of outputs that the Java compilation action will output in addition to the class jar from annotation processing. |
strict_deps
|
A string that specifies how to handle strict deps. Possible values: 'OFF', 'ERROR', 'WARN' and 'DEFAULT'. For more details see https://docs.bazel.build/versions/master/bazel-user-manual.html#flag--strict_java_deps. By default 'ERROR'. |
java_toolchain
|
A JavaToolchainInfo to be used for this compilation. Mandatory. |
host_javabase
|
A JavaRuntimeInfo to be used for this compilation. Mandatory. |
sourcepath
|
|
resources
|
|
neverlink
|
compile_time_jdeps
depset java_common.compile_time_jdeps(java_info)Experimental. This API is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting
--experimental_google_legacy_api
Returns a depset of the given JavaInfo's compile-time jdeps files.
Parameters
Parameter | Description |
---|---|
java_info
|
The JavaInfo to query. |
experimental_disable_annotation_processing
JavaInfo java_common.experimental_disable_annotation_processing(java_info)Experimental. This API is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting
--experimental_google_legacy_api
Returns a copy of the given JavaInfo with any provided annotation processors disabled. Annotation processor classpaths are preserved in case they contain Error Prone plugins, but processor names and data are excluded. For example, it can be used to process the inputs to java_common.compile's deps and plugins parameters.
Parameters
Parameter | Description |
---|---|
java_info
|
The JavaInfo to process. |
java_toolchain_label
Label java_common.java_toolchain_label(java_toolchain)Experimental. This API is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting
--experimental_google_legacy_api
Returns the toolchain's label.
Parameters
Parameter | Description |
---|---|
java_toolchain
|
The toolchain. |
JavaRuntimeInfo
Provider java_common.JavaRuntimeInfoThe key used to retrieve the provider that contains information about the Java runtime being used.
JavaToolchainInfo
Provider java_common.JavaToolchainInfoThe key used to retrieve the provider that contains information about the Java toolchain being used.
make_non_strict
JavaInfo java_common.make_non_strict(java_info)Returns a new Java provider whose direct-jars part is the union of both the direct and indirect jars of the given Java provider.
Parameters
Parameter | Description |
---|---|
java_info
|
The java info. |
merge
JavaInfo java_common.merge(providers)Merges the given providers into a single JavaInfo.
Parameters
Parameter | Description |
---|---|
providers
|
The list of providers to merge. |
MessageBundleInfo
Provider java_common.MessageBundleInfoExperimental. This API is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting
--experimental_google_legacy_api
The provider used to supply message bundles for translation
pack_sources
File java_common.pack_sources(actions, *, output_jar, sources=[], source_jars=[], java_toolchain, host_javabase)Packs sources and source jars into a single source jar file. The return value is typically passed to
JavaInfo#source_jar
Parameters
Parameter | Description |
---|---|
actions
|
ctx.actions |
output_jar
|
The output jar of the rule. Used to name the resulting source jar. |
sources
|
A list of Java source files to be packed into the source jar. |
source_jars
|
A list of source jars to be packed into the source jar. |
java_toolchain
|
A JavaToolchainInfo to used to find the ijar tool. |
host_javabase
|
A JavaRuntimeInfo to be used for packing sources. |
None
.
provider
Provider java_common.providerReturns the Java declared provider.
The same value is accessible as
JavaInfo
. Prefer using
JavaInfo
in new code.
run_ijar
File java_common.run_ijar(actions, *, jar, target_label=None, java_toolchain)Runs ijar on a jar, stripping it of its method bodies. This helps reduce rebuilding of dependent jars during any recompiles consisting only of simple changes to method implementations. The return value is typically passed to
JavaInfo#compile_jar
.
Parameters
Parameter | Description |
---|---|
actions
|
ctx.actions |
jar
|
The jar to run ijar on. |
target_label
|
A target label to stamp the jar with. Used for |
java_toolchain
|
A JavaToolchainInfo to used to find the ijar tool. |
stamp_jar
File java_common.stamp_jar(actions, *, jar, target_label, java_toolchain)Stamps a jar with a target label for
add_dep
support. The return value is typically passed to JavaInfo#compile_jar
. Prefer to use run_ijar
when possible.
Parameters
Parameter | Description |
---|---|
actions
|
ctx.actions |
jar
|
The jar to run stamp_jar on. |
target_label
|
A target label to stamp the jar with. Used for |
java_toolchain
|
A JavaToolchainInfo to used to find the stamp_jar tool. |