<html devsite>
<head>
  <meta name="project_path" value="/_project.yaml">
  <meta name="book_path" value="/versions/6.4.0/_book.yaml">
</head>
<body>

<h1 class="page-title" id="modules.java_common">java_common</h1>

<!-- {% raw %} -->

Utilities for Java compilation support in Starlark.

<h2>Members</h2>
<ul>
    <li>
    <a href="#BootClassPathInfo">BootClassPathInfo</a>
  </li>
      <li>
    <a href="#compile">compile</a>
  </li>
      <li>
    <a href="#JavaPluginInfo">JavaPluginInfo</a>
  </li>
      <li>
    <a href="#JavaRuntimeInfo">JavaRuntimeInfo</a>
  </li>
      <li>
    <a href="#JavaToolchainInfo">JavaToolchainInfo</a>
  </li>
      <li>
    <a href="#make_non_strict">make_non_strict</a>
  </li>
      <li>
    <a href="#merge">merge</a>
  </li>
      <li>
    <a href="#pack_sources">pack_sources</a>
  </li>
      <li>
    <a href="#provider">provider</a>
  </li>
      <li>
    <a href="#run_ijar">run_ijar</a>
  </li>
      <li>
    <a href="#stamp_jar">stamp_jar</a>
  </li>
      <li>
    <a href="#to_java_binary_info">to_java_binary_info</a>
  </li>
  </ul>

      <h2 id="BootClassPathInfo">BootClassPathInfo</h2>
        <p><pre class="rule-signature"><a class="anchor" href="Provider.html">Provider</a> java_common.BootClassPathInfo</pre></p>

    The provider used to supply bootclasspath information


        <h2 id="compile">compile</h2>
        <p><pre class="rule-signature"><a class="anchor" href="JavaInfo.html">JavaInfo</a> java_common.compile(ctx, *, source_jars=[], source_files=[], output, output_source_jar=None, javac_opts=[], deps=[], runtime_deps=[], exports=[], plugins=[], exported_plugins=[], native_libraries=[], annotation_processor_additional_inputs=[], annotation_processor_additional_outputs=[], strict_deps='ERROR', java_toolchain, host_javabase=None, sourcepath=[], resources=[], resource_jars=[], classpath_resources=[], neverlink=False, enable_annotation_processing=True, enable_compile_jar_action=True, add_exports=[], add_opens=[])</pre></p>

    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.

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="compile.ctx">
              <code>ctx</code>
            </td>
            <td>
                                     required<br/>
                          The rule context.
            </td>
          </tr>
                  <tr>
            <td id="compile.source_jars">
              <code>source_jars</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>
                          A list of the jars to be compiled. At least one of source_jars or source_files should be specified.
            </td>
          </tr>
                  <tr>
            <td id="compile.source_files">
              <code>source_files</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>
                          A list of the Java source files to be compiled. At least one of source_jars or source_files should be specified.
            </td>
          </tr>
                  <tr>
            <td id="compile.output">
              <code>output</code>
            </td>
            <td>
                                     required<br/>

            </td>
          </tr>
                  <tr>
            <td id="compile.output_source_jar">
              <code>output_source_jar</code>
            </td>
            <td>
                          <code><a class="anchor" href="File.html">File</a>; or <a class="anchor" href="globals.html#None">None</a></code>;
                                     default = None<br/>
                          The output source jar. Optional. Defaults to `{output_jar}-src.jar` if unset.
            </td>
          </tr>
                  <tr>
            <td id="compile.javac_opts">
              <code>javac_opts</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
                                     default = []<br/>
                          A list of the desired javac options. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.deps">
              <code>deps</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaInfo.html">JavaInfo</a>s</code>;
                                     default = []<br/>
                          A list of dependencies. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.runtime_deps">
              <code>runtime_deps</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaInfo.html">JavaInfo</a>s</code>;
                                     default = []<br/>
                          A list of runtime dependencies. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.exports">
              <code>exports</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaInfo.html">JavaInfo</a>s</code>;
                                     default = []<br/>
                          A list of exports. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.plugins">
              <code>plugins</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaPluginInfo.html">JavaPluginInfo</a>s; or <a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaInfo.html">JavaInfo</a>s</code>;
                                     default = []<br/>
                          A list of plugins. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.exported_plugins">
              <code>exported_plugins</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaPluginInfo.html">JavaPluginInfo</a>s; or <a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaInfo.html">JavaInfo</a>s</code>;
                                     default = []<br/>
                          A list of exported plugins. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.native_libraries">
              <code>native_libraries</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="CcInfo.html">CcInfo</a>s</code>;
                                     default = []<br/>
                          CC native library dependencies that are needed for this library.
            </td>
          </tr>
                  <tr>
            <td id="compile.annotation_processor_additional_inputs">
              <code>annotation_processor_additional_inputs</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>
                          A list of inputs that the Java compilation action will take in addition to the Java sources for annotation processing.
            </td>
          </tr>
                  <tr>
            <td id="compile.annotation_processor_additional_outputs">
              <code>annotation_processor_additional_outputs</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>
                          A list of outputs that the Java compilation action will output in addition to the class jar from annotation processing.
            </td>
          </tr>
                  <tr>
            <td id="compile.strict_deps">
              <code>strict_deps</code>
            </td>
            <td>
                                     default = 'ERROR'<br/>
                          A string that specifies how to handle strict deps. Possible values: 'OFF', 'ERROR', 'WARN' and 'DEFAULT'. For more details see /docs/user-manual#flag--strict_java_deps. By default 'ERROR'.
            </td>
          </tr>
                  <tr>
            <td id="compile.java_toolchain">
              <code>java_toolchain</code>
            </td>
            <td>
                                     required<br/>
                          A JavaToolchainInfo to be used for this compilation. Mandatory.
            </td>
          </tr>
                  <tr>
            <td id="compile.host_javabase">
              <code>host_javabase</code>
            </td>
            <td>
                                     default = None<br/>
                          <b>Deprecated</b>. This parameter is deprecated and will be removed soon. Please do not depend on it. It is <i>disabled</i> with <code>--+incompatible_java_common_parameters</code>. Use this flag to verify your code is compatible with its imminent removal. <br>Deprecated: You can drop this parameter (host_javabase is provided with java_toolchain)
            </td>
          </tr>
                  <tr>
            <td id="compile.sourcepath">
              <code>sourcepath</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>

            </td>
          </tr>
                  <tr>
            <td id="compile.resources">
              <code>resources</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>

            </td>
          </tr>
                  <tr>
            <td id="compile.resource_jars">
              <code>resource_jars</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>

            </td>
          </tr>
                  <tr>
            <td id="compile.classpath_resources">
              <code>classpath_resources</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>

            </td>
          </tr>
                  <tr>
            <td id="compile.neverlink">
              <code>neverlink</code>
            </td>
            <td>
                                     default = False<br/>

            </td>
          </tr>
                  <tr>
            <td id="compile.enable_annotation_processing">
              <code>enable_annotation_processing</code>
            </td>
            <td>
                                     default = True<br/>
                          Disables annotation processing in this compilation, causing any annotation processors provided in plugins or in exported_plugins of deps to be ignored.
            </td>
          </tr>
                  <tr>
            <td id="compile.enable_compile_jar_action">
              <code>enable_compile_jar_action</code>
            </td>
            <td>
                                     default = True<br/>
                          Enables header compilation or ijar creation. If set to False, it forces use of the full class jar in the compilation classpaths of any dependants. Doing so is intended for use by non-library targets such as binaries that do not have dependants.
            </td>
          </tr>
                  <tr>
            <td id="compile.add_exports">
              <code>add_exports</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
                                     default = []<br/>
                          Allow this library to access the given <module>/<package>. Optional.
            </td>
          </tr>
                  <tr>
            <td id="compile.add_opens">
              <code>add_opens</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
                                     default = []<br/>
                          Allow this library to reflectively access the given <module>/<package>. Optional.
            </td>
          </tr>
                </tbody>
      </table>

        <h2 id="JavaPluginInfo">JavaPluginInfo</h2>
        <p><pre class="rule-signature"><a class="anchor" href="Provider.html">Provider</a> java_common.JavaPluginInfo</pre></p>

    The key used to retrieve the provider that contains information about the Java plugins. The same value is accessible as <code>JavaPluginInfo</code>. <br>Prefer using <code>JavaPluginInfo</code> in new code.


        <h2 id="JavaRuntimeInfo">JavaRuntimeInfo</h2>
        <p><pre class="rule-signature"><a class="anchor" href="Provider.html">Provider</a> java_common.JavaRuntimeInfo</pre></p>

    The key used to retrieve the provider that contains information about the Java runtime being used.


        <h2 id="JavaToolchainInfo">JavaToolchainInfo</h2>
        <p><pre class="rule-signature"><a class="anchor" href="Provider.html">Provider</a> java_common.JavaToolchainInfo</pre></p>

    The key used to retrieve the provider that contains information about the Java toolchain being used.


        <h2 id="make_non_strict">make_non_strict</h2>
        <p><pre class="rule-signature"><a class="anchor" href="JavaInfo.html">JavaInfo</a> java_common.make_non_strict(java_info)</pre></p>

    Returns a new Java provider whose direct-jars part is the union of both the direct and indirect jars of the given Java provider.

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="make_non_strict.java_info">
              <code>java_info</code>
            </td>
            <td>
                                     required<br/>
                          The java info.
            </td>
          </tr>
                </tbody>
      </table>

        <h2 id="merge">merge</h2>
        <p><pre class="rule-signature"><a class="anchor" href="JavaInfo.html">JavaInfo</a> java_common.merge(providers, *, merge_java_outputs=True, merge_source_jars=True)</pre></p>

    Merges the given providers into a single JavaInfo.

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="merge.providers">
              <code>providers</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="JavaInfo.html">JavaInfo</a>s</code>;
                                     required<br/>
                          The list of providers to merge.
            </td>
          </tr>
                  <tr>
            <td id="merge.merge_java_outputs">
              <code>merge_java_outputs</code>
            </td>
            <td>
                                     default = True<br/>

            </td>
          </tr>
                  <tr>
            <td id="merge.merge_source_jars">
              <code>merge_source_jars</code>
            </td>
            <td>
                                     default = True<br/>

            </td>
          </tr>
                </tbody>
      </table>

        <h2 id="pack_sources">pack_sources</h2>
        <p><pre class="rule-signature"><a class="anchor" href="File.html">File</a> java_common.pack_sources(actions, *, output_jar=None, output_source_jar=None, sources=[], source_jars=[], java_toolchain, host_javabase=None)</pre></p>

    Packs sources and source jars into a single source jar file. The return value is typically passed to<p><code><a class="anchor" href="JavaInfo.html">JavaInfo</a>#source_jar</code></p>.At least one of parameters output_jar or output_source_jar is required.

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="pack_sources.actions">
              <code>actions</code>
            </td>
            <td>
                                     required<br/>
                          ctx.actions
            </td>
          </tr>
                  <tr>
            <td id="pack_sources.output_jar">
              <code>output_jar</code>
            </td>
            <td>
                          <code><a class="anchor" href="File.html">File</a>; or <a class="anchor" href="globals.html#None">None</a></code>;
                                     default = None<br/>
                          <b>Deprecated</b>. This parameter is deprecated and will be removed soon. Please do not depend on it. It is <i>disabled</i> with <code>--+incompatible_java_common_parameters</code>. Use this flag to verify your code is compatible with its imminent removal. <br>Deprecated: The output jar of the rule. Used to name the resulting source jar. The parameter sets output_source_jar parameter to `{output_jar}-src.jar`.Use output_source_jar parameter directly instead.
            </td>
          </tr>
                  <tr>
            <td id="pack_sources.output_source_jar">
              <code>output_source_jar</code>
            </td>
            <td>
                          <code><a class="anchor" href="File.html">File</a>; or <a class="anchor" href="globals.html#None">None</a></code>;
                                     default = None<br/>
                          The output source jar.
            </td>
          </tr>
                  <tr>
            <td id="pack_sources.sources">
              <code>sources</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>
                          A list of Java source files to be packed into the source jar.
            </td>
          </tr>
                  <tr>
            <td id="pack_sources.source_jars">
              <code>source_jars</code>
            </td>
            <td>
                          <code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="File.html">File</a>s</code>;
                                     default = []<br/>
                          A list of source jars to be packed into the source jar.
            </td>
          </tr>
                  <tr>
            <td id="pack_sources.java_toolchain">
              <code>java_toolchain</code>
            </td>
            <td>
                                     required<br/>
                          A JavaToolchainInfo to used to find the ijar tool.
            </td>
          </tr>
                  <tr>
            <td id="pack_sources.host_javabase">
              <code>host_javabase</code>
            </td>
            <td>
                                     default = None<br/>
                          <b>Deprecated</b>. This parameter is deprecated and will be removed soon. Please do not depend on it. It is <i>disabled</i> with <code>--+incompatible_java_common_parameters</code>. Use this flag to verify your code is compatible with its imminent removal. <br>Deprecated: You can drop this parameter (host_javabase is provided with java_toolchain)
            </td>
          </tr>
                </tbody>
      </table>
         May return <code>None</code>.

        <h2 id="provider">provider</h2>
        <p><pre class="rule-signature"><a class="anchor" href="Provider.html">Provider</a> java_common.provider</pre></p>

    Returns the Java declared provider. <br>The same value is accessible as <code>JavaInfo</code>. <br>Prefer using <code>JavaInfo</code> in new code.


        <h2 id="run_ijar">run_ijar</h2>
        <p><pre class="rule-signature"><a class="anchor" href="File.html">File</a> java_common.run_ijar(actions, *, jar, target_label=None, java_toolchain)</pre></p>

    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 <code><a class="anchor" href="JavaInfo.html">JavaInfo</a>#compile_jar</code>.

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="run_ijar.actions">
              <code>actions</code>
            </td>
            <td>
                                     required<br/>
                          ctx.actions
            </td>
          </tr>
                  <tr>
            <td id="run_ijar.jar">
              <code>jar</code>
            </td>
            <td>
                                     required<br/>
                          The jar to run ijar on.
            </td>
          </tr>
                  <tr>
            <td id="run_ijar.target_label">
              <code>target_label</code>
            </td>
            <td>
                          <code><a class="anchor" href="Label.html">Label</a>; or <a class="anchor" href="globals.html#None">None</a></code>;
                                     default = None<br/>
                          A target label to stamp the jar with. Used for <code>add_dep</code> support. Typically, you would pass <code>ctx.label</code> to stamp the jar with the current rule's label.
            </td>
          </tr>
                  <tr>
            <td id="run_ijar.java_toolchain">
              <code>java_toolchain</code>
            </td>
            <td>
                                     required<br/>
                          A JavaToolchainInfo to used to find the ijar tool.
            </td>
          </tr>
                </tbody>
      </table>

        <h2 id="stamp_jar">stamp_jar</h2>
        <p><pre class="rule-signature"><a class="anchor" href="File.html">File</a> java_common.stamp_jar(actions, *, jar, target_label, java_toolchain)</pre></p>

    Stamps a jar with a target label for <code>add_dep</code> support. The return value is typically passed to <code><a class="anchor" href="JavaInfo.html">JavaInfo</a>#compile_jar</code>. Prefer to use <code><a class="anchor" href="java_common.html#run_ijar">run_ijar</a></code> when possible.

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="stamp_jar.actions">
              <code>actions</code>
            </td>
            <td>
                                     required<br/>
                          ctx.actions
            </td>
          </tr>
                  <tr>
            <td id="stamp_jar.jar">
              <code>jar</code>
            </td>
            <td>
                                     required<br/>
                          The jar to run stamp_jar on.
            </td>
          </tr>
                  <tr>
            <td id="stamp_jar.target_label">
              <code>target_label</code>
            </td>
            <td>
                                     required<br/>
                          A target label to stamp the jar with. Used for <code>add_dep</code> support. Typically, you would pass <code>ctx.label</code> to stamp the jar with the current rule's label.
            </td>
          </tr>
                  <tr>
            <td id="stamp_jar.java_toolchain">
              <code>java_toolchain</code>
            </td>
            <td>
                                     required<br/>
                          A JavaToolchainInfo to used to find the stamp_jar tool.
            </td>
          </tr>
                </tbody>
      </table>

        <h2 id="to_java_binary_info">to_java_binary_info</h2>
        <p><pre class="rule-signature"><a class="anchor" href="JavaInfo.html">JavaInfo</a> java_common.to_java_binary_info(java_info)</pre></p>

    Returns a copy of the given JavaInfo with minimal info returned by a java_binary

          <!-- hide-from-toc is a class used by DevSite for the public Bazel site
      (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
      <h3 class="hide-from-toc">Parameters</h3>
      <table class="table table-bordered table-condensed table-params">
        <colgroup>
          <col class="col-param">
          <col class="param-description">
        </colgroup>
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
                  <tr>
            <td id="to_java_binary_info.java_info">
              <code>java_info</code>
            </td>
            <td>
                                     required<br/>
                          The JavaInfo to enhance.
            </td>
          </tr>
                </tbody>
      </table>


</body>
</html>

<!-- {% endraw %} -->
