CINXE.COM
Java Rules | Bazel
<!doctype html> <html lang="en" dir="ltr"> <head> <meta name="google-signin-client-id" content="157101835696-ooapojlodmuabs2do2vuhhnf90bccmoi.apps.googleusercontent.com"> <meta name="google-signin-scope" content="profile email https://www.googleapis.com/auth/developerprofiles https://www.googleapis.com/auth/developerprofiles.award"> <meta property="og:site_name" content="Bazel"> <meta property="og:type" content="website"><meta name="theme-color" content="#0c713a"><meta charset="utf-8"> <meta content="IE=Edge" http-equiv="X-UA-Compatible"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="manifest" href="/_pwa/bazel/manifest.json" crossorigin="use-credentials"> <link rel="preconnect" href="//www.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.googleapis.com" crossorigin> <link rel="preconnect" href="//apis.google.com" crossorigin> <link rel="preconnect" href="//www.google-analytics.com" crossorigin><link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap"> <link rel="stylesheet" href="//fonts.googleapis.com/css2?family=Material+Icons&family=Material+Symbols+Outlined&display=block"><link rel="stylesheet" href="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/css/app.css"> <link rel="shortcut icon" href="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/favicon-prod.png"> <link rel="apple-touch-icon" href="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/touchicon-180.png"><link rel="canonical" href="https://bazel.build/reference/be/java"><link rel="search" type="application/opensearchdescription+xml" title="Bazel" href="https://bazel.build/s/opensearch.xml"> <link rel="alternate" hreflang="en" href="https://bazel.build/reference/be/java" /><link rel="alternate" hreflang="x-default" href="https://bazel.build/reference/be/java" /><link rel="alternate" hreflang="ar" href="https://bazel.build/reference/be/java?hl=ar" /><link rel="alternate" hreflang="bn" href="https://bazel.build/reference/be/java?hl=bn" /><link rel="alternate" hreflang="zh-Hans" href="https://bazel.build/reference/be/java?hl=zh-cn" /><link rel="alternate" hreflang="zh-Hant" href="https://bazel.build/reference/be/java?hl=zh-tw" /><link rel="alternate" hreflang="fa" href="https://bazel.build/reference/be/java?hl=fa" /><link rel="alternate" hreflang="fr" href="https://bazel.build/reference/be/java?hl=fr" /><link rel="alternate" hreflang="he" href="https://bazel.build/reference/be/java?hl=he" /><link rel="alternate" hreflang="hi" href="https://bazel.build/reference/be/java?hl=hi" /><link rel="alternate" hreflang="id" href="https://bazel.build/reference/be/java?hl=id" /><link rel="alternate" hreflang="it" href="https://bazel.build/reference/be/java?hl=it" /><link rel="alternate" hreflang="ja" href="https://bazel.build/reference/be/java?hl=ja" /><link rel="alternate" hreflang="ko" href="https://bazel.build/reference/be/java?hl=ko" /><link rel="alternate" hreflang="pl" href="https://bazel.build/reference/be/java?hl=pl" /><link rel="alternate" hreflang="pt-BR" href="https://bazel.build/reference/be/java?hl=pt-br" /><link rel="alternate" hreflang="ru" href="https://bazel.build/reference/be/java?hl=ru" /><link rel="alternate" hreflang="es-419" href="https://bazel.build/reference/be/java?hl=es-419" /><link rel="alternate" hreflang="th" href="https://bazel.build/reference/be/java?hl=th" /><link rel="alternate" hreflang="tr" href="https://bazel.build/reference/be/java?hl=tr" /><link rel="alternate" hreflang="vi" href="https://bazel.build/reference/be/java?hl=vi" /><link rel="alternate" hreflang="en-cn" href="https://bazel.google.cn/reference/be/java" /><link rel="alternate" hreflang="x-default" href="https://bazel.google.cn/reference/be/java" /><link rel="alternate" hreflang="ar-cn" href="https://bazel.google.cn/reference/be/java?hl=ar" /><link rel="alternate" hreflang="bn-cn" href="https://bazel.google.cn/reference/be/java?hl=bn" /><link rel="alternate" hreflang="zh-Hans-cn" href="https://bazel.google.cn/reference/be/java?hl=zh-cn" /><link rel="alternate" hreflang="zh-Hant-cn" href="https://bazel.google.cn/reference/be/java?hl=zh-tw" /><link rel="alternate" hreflang="fa-cn" href="https://bazel.google.cn/reference/be/java?hl=fa" /><link rel="alternate" hreflang="fr-cn" href="https://bazel.google.cn/reference/be/java?hl=fr" /><link rel="alternate" hreflang="he-cn" href="https://bazel.google.cn/reference/be/java?hl=he" /><link rel="alternate" hreflang="hi-cn" href="https://bazel.google.cn/reference/be/java?hl=hi" /><link rel="alternate" hreflang="id-cn" href="https://bazel.google.cn/reference/be/java?hl=id" /><link rel="alternate" hreflang="it-cn" href="https://bazel.google.cn/reference/be/java?hl=it" /><link rel="alternate" hreflang="ja-cn" href="https://bazel.google.cn/reference/be/java?hl=ja" /><link rel="alternate" hreflang="ko-cn" href="https://bazel.google.cn/reference/be/java?hl=ko" /><link rel="alternate" hreflang="pl-cn" href="https://bazel.google.cn/reference/be/java?hl=pl" /><link rel="alternate" hreflang="pt-BR-cn" href="https://bazel.google.cn/reference/be/java?hl=pt-br" /><link rel="alternate" hreflang="ru-cn" href="https://bazel.google.cn/reference/be/java?hl=ru" /><link rel="alternate" hreflang="es-419-cn" href="https://bazel.google.cn/reference/be/java?hl=es-419" /><link rel="alternate" hreflang="th-cn" href="https://bazel.google.cn/reference/be/java?hl=th" /><link rel="alternate" hreflang="tr-cn" href="https://bazel.google.cn/reference/be/java?hl=tr" /><link rel="alternate" hreflang="vi-cn" href="https://bazel.google.cn/reference/be/java?hl=vi" /><title>Java Rules | Bazel</title> <meta property="og:title" content="Java Rules | Bazel"><meta property="og:url" content="https://bazel.build/reference/be/java"><meta property="og:locale" content="en"><script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "headline": "Java Rules" } </script> <link rel="stylesheet" href="/extras.css"></head> <body class="" template="page" theme="bazel-theme" type="article" layout="docs" display-toc pending> <devsite-progress type="indeterminate" id="app-progress"></devsite-progress> <a href="#main-content" class="skip-link button"> Skip to main content </a> <section class="devsite-wrapper"> <devsite-cookie-notification-bar></devsite-cookie-notification-bar><devsite-header role="banner"> <div class="devsite-header--inner" data-nosnippet> <div class="devsite-top-logo-row-wrapper-wrapper"> <div class="devsite-top-logo-row-wrapper"> <div class="devsite-top-logo-row"> <button type="button" id="devsite-hamburger-menu" class="devsite-header-icon-button button-flat material-icons gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Navigation menu button" visually-hidden aria-label="Open menu"> </button> <div class="devsite-product-name-wrapper"> <a href="/" class="devsite-site-logo-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Site logo" track-type="globalNav" track-name="bazel" track-metadata-position="nav" track-metadata-eventDetail="nav"> <picture> <img src="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/lockup.svg" class="devsite-site-logo" alt="Bazel"> </picture> </a> <span class="devsite-product-name"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> </li> </ul> </span> </div> <div class="devsite-top-logo-row-middle"> <div class="devsite-header-upper-tabs"> <devsite-tabs class="upper-tabs"> <nav class="devsite-tabs-wrapper" aria-label="Upper tabs"> <tab > <a href="https://bazel.build/about" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/about" track-type="nav" track-metadata-position="nav - about bazel" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: About Bazel" track-name="about bazel" > About Bazel </a> </tab> <tab > <a href="https://bazel.build/start" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/start" track-type="nav" track-metadata-position="nav - getting started" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Getting started" track-name="getting started" > Getting started </a> </tab> <tab > <a href="https://bazel.build/docs" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/docs" track-type="nav" track-metadata-position="nav - user guide" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: User guide" track-name="user guide" > User guide </a> </tab> <tab class="devsite-active"> <a href="https://bazel.build/reference" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference" track-type="nav" track-metadata-position="nav - reference" track-metadata-module="primary nav" aria-label="Reference, selected" data-category="Site-Wide Custom Events" data-label="Tab: Reference" track-name="reference" > Reference </a> </tab> <tab > <a href="https://bazel.build/extending" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/extending" track-type="nav" track-metadata-position="nav - extending" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Extending" track-name="extending" > Extending </a> </tab> <tab > <a href="https://bazel.build/community" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/community" track-type="nav" track-metadata-position="nav - community" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" > Community </a> </tab> <tab class="devsite-dropdown "> <a href="https://bazel.build/versions" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/versions" track-type="nav" track-metadata-position="nav - versioned docs" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" > Versioned docs </a> <button aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown menu for Versioned docs" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions" track-metadata-position="nav - versioned docs" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></button> <div class="devsite-tabs-dropdown" role="menu" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/8.0.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/8.0.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 8.0 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.6.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.6.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.6 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.5.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.5.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.5 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.4.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.4.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.4 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.0.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.0.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.0 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/6.5.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/6.5.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 6.5 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://docs.bazel.build/versions/5.4.1/bazel-overview.html" track-type="nav" track-metadata-eventdetail="https://docs.bazel.build/versions/5.4.1/bazel-overview.html" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 5.4.1 </div> </a> </li> </ul> </div> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://bazel.build/" track-type="nav" track-metadata-eventdetail="https://bazel.build/" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Nightly </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> More… </div> </a> </li> </ul> </div> </div> </div> </tab> </nav> </devsite-tabs> </div> <devsite-search enable-signin enable-search enable-suggestions enable-query-completion project-name="Bazel" tenant-name="Bazel" > <form class="devsite-search-form" action="https://bazel.build/s/results" method="GET"> <div class="devsite-search-container"> <button type="button" search-open class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Open search"></button> <div class="devsite-searchbox"> <input aria-activedescendant="" aria-autocomplete="list" aria-label="Search" aria-expanded="false" aria-haspopup="listbox" autocomplete="off" class="devsite-search-field devsite-search-query" name="q" placeholder="Search" role="combobox" type="text" value="" > <div class="devsite-search-image material-icons" aria-hidden="true"> </div> <div class="devsite-search-shortcut-icon-container" aria-hidden="true"> <kbd class="devsite-search-shortcut-icon">/</kbd> </div> </div> </div> </form> <button type="button" search-close class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Close search"></button> </devsite-search> </div> <devsite-language-selector> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" >English</a> </li> <li role="presentation"> <a role="menuitem" lang="es_419" >Español – América Latina</a> </li> <li role="presentation"> <a role="menuitem" lang="fr" >Français</a> </li> <li role="presentation"> <a role="menuitem" lang="id" >Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="it" >Italiano</a> </li> <li role="presentation"> <a role="menuitem" lang="pl" >Polski</a> </li> <li role="presentation"> <a role="menuitem" lang="pt_br" >Português – Brasil</a> </li> <li role="presentation"> <a role="menuitem" lang="vi" >Tiếng Việt</a> </li> <li role="presentation"> <a role="menuitem" lang="tr" >Türkçe</a> </li> <li role="presentation"> <a role="menuitem" lang="ru" >Русский</a> </li> <li role="presentation"> <a role="menuitem" lang="he" >עברית</a> </li> <li role="presentation"> <a role="menuitem" lang="ar" >العربيّة</a> </li> <li role="presentation"> <a role="menuitem" lang="fa" >فارسی</a> </li> <li role="presentation"> <a role="menuitem" lang="hi" >हिंदी</a> </li> <li role="presentation"> <a role="menuitem" lang="bn" >বাংলা</a> </li> <li role="presentation"> <a role="menuitem" lang="th" >ภาษาไทย</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_cn" >中文 – 简体</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_tw" >中文 – 繁體</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" >日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" >한국어</a> </li> </ul> </devsite-language-selector> <a class="devsite-header-link devsite-top-button button gc-analytics-event " href="//github.com/bazelbuild/bazel/" data-category="Site-Wide Custom Events" data-label="Site header link: GitHub" > GitHub </a> <devsite-user enable-profiles id="devsite-user"> <span class="button devsite-top-button" aria-hidden="true" visually-hidden>Sign in</span> </devsite-user> </div> </div> </div> <div class="devsite-collapsible-section "> <div class="devsite-header-background"> <div class="devsite-product-id-row" > <div class="devsite-product-description-row"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> <a href="https://bazel.build/reference" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Lower Header" data-value="1" track-type="globalNav" track-name="breadcrumb" track-metadata-position="1" track-metadata-eventdetail="" > Searchable reference documents generated from Bazel's code </a> </li> </ul> </div> </div> <div class="devsite-doc-set-nav-row"> <devsite-tabs class="lower-tabs"> <nav class="devsite-tabs-wrapper" aria-label="Lower tabs"> <tab class="devsite-active"> <a href="https://bazel.build/reference/be/overview" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/be/overview" track-type="nav" track-metadata-position="nav - build encyclopedia" track-metadata-module="primary nav" aria-label="Build encyclopedia, selected" data-category="Site-Wide Custom Events" data-label="Tab: Build encyclopedia" track-name="build encyclopedia" > Build encyclopedia </a> </tab> <tab > <a href="https://bazel.build/reference/command-line-reference" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/command-line-reference" track-type="nav" track-metadata-position="nav - command line reference" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Command line reference" track-name="command line reference" > Command line reference </a> </tab> <tab > <a href="https://bazel.build/query/language" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/query/language" track-type="nav" track-metadata-position="nav - query language" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Query language" track-name="query language" > Query language </a> </tab> <tab > <a href="https://bazel.build/reference/glossary" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/glossary" track-type="nav" track-metadata-position="nav - glossary" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Glossary" track-name="glossary" > Glossary </a> </tab> <tab > <a href="https://bazel.build/reference/flag-cheatsheet" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/flag-cheatsheet" track-type="nav" track-metadata-position="nav - flag cheatsheet" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Flag cheatsheet" track-name="flag cheatsheet" > Flag cheatsheet </a> </tab> </nav> </devsite-tabs> </div> </div> </div> </div> </devsite-header> <devsite-book-nav scrollbars > <div class="devsite-book-nav-filter" > <span class="filter-list-icon material-icons" aria-hidden="true"></span> <input type="text" placeholder="Filter" aria-label="Type to filter" role="searchbox"> <span class="filter-clear-button hidden" data-title="Clear filter" aria-label="Clear filter" role="button" tabindex="0"></span> </div> <nav class="devsite-book-nav devsite-nav nocontent" aria-label="Side menu"> <div class="devsite-mobile-header"> <button type="button" id="devsite-close-nav" class="devsite-header-icon-button button-flat material-icons gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Close navigation" aria-label="Close navigation"> </button> <div class="devsite-product-name-wrapper"> <a href="/" class="devsite-site-logo-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Site logo" track-type="globalNav" track-name="bazel" track-metadata-position="nav" track-metadata-eventDetail="nav"> <picture> <img src="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/lockup.svg" class="devsite-site-logo" alt="Bazel"> </picture> </a> <span class="devsite-product-name"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> </li> </ul> </span> </div> </div> <div class="devsite-book-nav-wrapper"> <div class="devsite-mobile-nav-top"> <ul class="devsite-nav-list"> <li class="devsite-nav-item"> <a href="/about" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: About Bazel" track-name="about bazel" data-category="Site-Wide Custom Events" data-label="Responsive Tab: About Bazel" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > About Bazel </span> </a> </li> <li class="devsite-nav-item"> <a href="/start" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Getting started" track-name="getting started" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Getting started" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Getting started </span> </a> </li> <li class="devsite-nav-item"> <a href="/docs" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: User guide" track-name="user guide" data-category="Site-Wide Custom Events" data-label="Responsive Tab: User guide" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > User guide </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference" class="devsite-nav-title gc-analytics-event devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Reference" track-name="reference" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Reference" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Reference </span> </a> <ul class="devsite-nav-responsive-tabs"> <li class="devsite-nav-item"> <a href="/reference/be/overview" class="devsite-nav-title gc-analytics-event devsite-nav-has-children devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Build encyclopedia" track-name="build encyclopedia" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Build encyclopedia" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip menu="_book"> Build encyclopedia </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="_book"> </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference/command-line-reference" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Command line reference" track-name="command line reference" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Command line reference" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Command line reference </span> </a> </li> <li class="devsite-nav-item"> <a href="/query/language" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Query language" track-name="query language" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Query language" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Query language </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference/glossary" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Glossary" track-name="glossary" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Glossary" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Glossary </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference/flag-cheatsheet" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Flag cheatsheet" track-name="flag cheatsheet" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Flag cheatsheet" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Flag cheatsheet </span> </a> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/extending" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Extending" track-name="extending" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Extending" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Extending </span> </a> </li> <li class="devsite-nav-item"> <a href="/community" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Community" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Community </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Versioned docs" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Versioned docs </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" > <span class="devsite-nav-text" tooltip menu="Versioned docs"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="Versioned docs"> </span> </span> </li> </ul> </li> <li class="devsite-nav-item"> <a href="//github.com/bazelbuild/bazel/" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: GitHub" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > GitHub </span> </a> </li> </ul> </div> <div class="devsite-mobile-nav-bottom"> <ul class="devsite-nav-list" menu="_book"> <li class="devsite-nav-item devsite-nav-expandable"><div class="devsite-expandable-nav"> <a class="devsite-nav-toggle" aria-hidden="true"></a><div class="devsite-nav-title devsite-nav-title-no-path" tabindex="0" role="button"> <span class="devsite-nav-text" tooltip>Build encyclopedia</span> </div><ul class="devsite-nav-section"><li class="devsite-nav-item"><a href="/reference/be/overview" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/overview" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/overview" ><span class="devsite-nav-text" tooltip>Overview</span></a></li><li class="devsite-nav-item"><a href="/reference/be/common-definitions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/common-definitions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/common-definitions" ><span class="devsite-nav-text" tooltip>Common definitions</span></a></li><li class="devsite-nav-item"><a href="/reference/be/make-variables" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/make-variables" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/make-variables" ><span class="devsite-nav-text" tooltip>Make variables</span></a></li><li class="devsite-nav-item"><a href="/reference/be/functions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/functions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/functions" ><span class="devsite-nav-text" tooltip>Functions</span></a></li><li class="devsite-nav-item devsite-nav-expandable"><div class="devsite-expandable-nav"> <a class="devsite-nav-toggle" aria-hidden="true"></a><div class="devsite-nav-title devsite-nav-title-no-path" tabindex="0" role="button"> <span class="devsite-nav-text" tooltip>Core rules</span> </div><ul class="devsite-nav-section"><li class="devsite-nav-item"><a href="/reference/be/extra-actions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/extra-actions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/extra-actions" ><span class="devsite-nav-text" tooltip>Extra Actions</span></a></li><li class="devsite-nav-item"><a href="/reference/be/general" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/general" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/general" ><span class="devsite-nav-text" tooltip>General</span></a></li><li class="devsite-nav-item"><a href="/reference/be/platforms-and-toolchains" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/platforms-and-toolchains" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/platforms-and-toolchains" ><span class="devsite-nav-text" tooltip>Platforms and Toolchains</span></a></li><li class="devsite-nav-item"><a href="/reference/be/workspace" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/workspace" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/workspace" ><span class="devsite-nav-text" tooltip>Workspace</span></a></li></ul></div></li><li class="devsite-nav-item devsite-nav-expandable"><div class="devsite-expandable-nav"> <a class="devsite-nav-toggle" aria-hidden="true"></a><div class="devsite-nav-title devsite-nav-title-no-path" tabindex="0" role="button"> <span class="devsite-nav-text" tooltip>Language Specific rules</span> </div><ul class="devsite-nav-section"><li class="devsite-nav-item"><a href="/reference/be/c-cpp" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/c-cpp" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/c-cpp" ><span class="devsite-nav-text" tooltip>C / C++</span></a></li><li class="devsite-nav-item"><a href="/reference/be/java" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/java" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/java" ><span class="devsite-nav-text" tooltip>Java</span></a></li><li class="devsite-nav-item"><a href="/reference/be/objective-c" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/objective-c" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/objective-c" ><span class="devsite-nav-text" tooltip>Objective-C</span></a></li><li class="devsite-nav-item"><a href="/reference/be/protocol-buffer" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/protocol-buffer" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/protocol-buffer" ><span class="devsite-nav-text" tooltip>Protocol Buffer</span></a></li><li class="devsite-nav-item"><a href="/reference/be/python" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/python" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/python" ><span class="devsite-nav-text" tooltip>Python</span></a></li><li class="devsite-nav-item"><a href="/reference/be/shell" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/shell" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/shell" ><span class="devsite-nav-text" tooltip>Shell</span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_appengine" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_appengine" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_appengine" ><span class="devsite-nav-text" tooltip>AppEngine</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_apple" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_apple" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_apple" ><span class="devsite-nav-text" tooltip>Apple (Swift, iOS, macOS, tvOS, visionOS, watchOS)</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_dotnet" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_dotnet" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_dotnet" ><span class="devsite-nav-text" tooltip>C#</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_d" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_d" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_d" ><span class="devsite-nav-text" tooltip>D</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_docker" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_docker" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_docker" ><span class="devsite-nav-text" tooltip>Docker</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_groovy" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_groovy" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_groovy" ><span class="devsite-nav-text" tooltip>Groovy</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_go" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_go" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_go" ><span class="devsite-nav-text" tooltip>Go</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_closure" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_closure" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_closure" ><span class="devsite-nav-text" tooltip>JavaScript (Closure)</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_jsonnet" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_jsonnet" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_jsonnet" ><span class="devsite-nav-text" tooltip>Jsonnet</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_rust" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_rust" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_rust" ><span class="devsite-nav-text" tooltip>Rust</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_sass" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_sass" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_sass" ><span class="devsite-nav-text" tooltip>Sass</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_scala" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_scala" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_scala" ><span class="devsite-nav-text" tooltip>Scala</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li></ul></div></li></ul></div></li> <li class="devsite-nav-item"><a href="/reference/test-encyclopedia" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/test-encyclopedia" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/test-encyclopedia" ><span class="devsite-nav-text" tooltip>Test encyclopedia</span></a></li> </ul> <ul class="devsite-nav-list" menu="Versioned docs" aria-label="Side menu" hidden> <li class="devsite-nav-item"> <a href="/versions/8.0.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 8.0" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 8.0 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.6.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.6" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.6 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.5.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.5" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.5 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.4.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.4" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.4 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.0.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.0" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.0 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 6.5" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 6.5 </span> </a> </li> <li class="devsite-nav-item"> <a href="https://docs.bazel.build/versions/5.4.1/bazel-overview.html" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 5.4.1" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 5.4.1 </span> </a> </li> <li class="devsite-nav-item"> <a href="/" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Nightly" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Nightly </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: More…" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > More… </span> </a> </li> </ul> </div> </div> </nav> </devsite-book-nav> <section id="gc-wrapper"> <main role="main" id="main-content" class="devsite-main-content" has-book-nav has-sidebar > <div class="devsite-sidebar"> <div class="devsite-sidebar-content"> <devsite-toc class="devsite-nav" role="navigation" aria-label="On this page" depth="2" scrollbars ></devsite-toc> <devsite-recommendations-sidebar class="nocontent devsite-nav"> </devsite-recommendations-sidebar> </div> </div> <devsite-content> <article class="devsite-article"> <div class="devsite-article-meta nocontent" role="navigation"> <ul class="devsite-breadcrumb-list" aria-label="Breadcrumb"> <li class="devsite-breadcrumb-item "> <a href="https://bazel.build/" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="1" track-type="globalNav" track-name="breadcrumb" track-metadata-position="1" track-metadata-eventdetail="Bazel" > Bazel </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://bazel.build/reference" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="2" track-type="globalNav" track-name="breadcrumb" track-metadata-position="2" track-metadata-eventdetail="" > Reference </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://bazel.build/reference/be/overview" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="3" track-type="globalNav" track-name="breadcrumb" track-metadata-position="3" track-metadata-eventdetail="" > Build encyclopedia </a> </li> </ul> <devsite-thumb-rating position="header"> </devsite-thumb-rating> </div> <devsite-feedback position="header" project-name="Bazel" product-id="5052038" bucket="https-bazel-build" context="" version="t-devsite-webserver-20250325-r00-rc03.468100743126793331" data-label="Send Feedback Button" track-type="feedback" track-name="sendFeedbackLink" track-metadata-position="header" class="nocontent" project-icon="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/touchicon-180.png" > <button> Send feedback </button> </devsite-feedback> <h1 class="devsite-page-title" tabindex="-1"> Java Rules <div class="devsite-actions" data-nosnippet><devsite-feature-tooltip ack-key="AckCollectionsBookmarkTooltipDismiss" analytics-category="Site-Wide Custom Events" analytics-action-show="Callout Profile displayed" analytics-action-close="Callout Profile dismissed" analytics-label="Create Collection Callout" class="devsite-page-bookmark-tooltip nocontent" dismiss-button="true" id="devsite-collections-dropdown" dismiss-button-text="Dismiss" close-button-text="Got it"> <devsite-bookmark></devsite-bookmark> <span slot="popout-heading"> Stay organized with collections </span> <span slot="popout-contents"> Save and categorize content based on your preferences. </span> </devsite-feature-tooltip></div> </h1> <div class="devsite-page-title-meta"><devsite-view-release-notes></devsite-view-release-notes></div> <devsite-toc class="devsite-nav" depth="2" devsite-toc-embedded > </devsite-toc> <div class="devsite-article-body clearfix "> <!-- This document is synchronized with Bazel releases. To edit, submit changes to the Bazel source code. --> <!-- Generated by //src/main/java/com/google/devtools/build/docgen:build-encyclopedia.zip --> <html> <body> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/issues/new?title=%5Bbazel.build%5D+Problem+with+/reference/be/java&template=doc_issue.yml&link=https%3A%2F%2Fbazel.build/reference/be/java" target="_blank"> Report an issue<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/tree/master/src/main/java/com/google/devtools/build/docgen/templates/be/rules.vm" target="_blank"> View source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <span style="float: right; line-height: 36px"> <strong>Nightly</strong> <!-- The lines below are updated by //scripts/docs:gen_new_toc --> <!-- BEGIN_VERSION_INDICATOR --> · <a href="/versions/8.1.0/reference/be/java">8.1</a> · <a href="/versions/8.0.0/reference/be/java">8.0</a> · <a href="/versions/7.6.0/reference/be/java">7.6</a> · <a href="/versions/7.5.0/reference/be/java">7.5</a> · <a href="/versions/7.4.0/reference/be/java">7.4</a> <!-- END_VERSION_INDICATOR --> </span> <p/> <h2 id="rules" data-text="Rules" tabindex="-1">Rules</h2> <ul> <li> <a href="#java_binary"> java_binary </a> </li> <li> <a href="#java_import"> java_import </a> </li> <li> <a href="#java_library"> java_library </a> </li> <li> <a href="#java_test"> java_test </a> </li> <li> <a href="#java_package_configuration"> java_package_configuration </a> </li> <li> <a href="#java_plugin"> java_plugin </a> </li> <li> <a href="#java_runtime"> java_runtime </a> </li> <li> <a href="#java_single_jar"> java_single_jar </a> </li> <li> <a href="#java_toolchain"> java_toolchain </a> </li> </ul> <h2 id="java_binary" data-text=" java_binary " tabindex="-1"> java_binary </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/bazel/rules/bazel_java_binary.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_binary(<a href="#java_binary.name">name</a>, <a href="#java_binary.deps">deps</a>, <a href="#java_binary.srcs">srcs</a>, <a href="#java_binary.data">data</a>, <a href="#java_binary.resources">resources</a>, <a href="#java_binary.add_exports">add_exports</a>, <a href="#java_binary.add_opens">add_opens</a>, <a href="/reference/be/common-definitions#binary.args">args</a>, <a href="#java_binary.bootclasspath">bootclasspath</a>, <a href="#java_binary.classpath_resources">classpath_resources</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#java_binary.create_executable">create_executable</a>, <a href="#java_binary.deploy_env">deploy_env</a>, <a href="#java_binary.deploy_manifest_lines">deploy_manifest_lines</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#binary.env">env</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_binary.javacopts">javacopts</a>, <a href="#java_binary.jvm_flags">jvm_flags</a>, <a href="#java_binary.launcher">launcher</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#java_binary.main_class">main_class</a>, <a href="#java_binary.neverlink">neverlink</a>, <a href="/reference/be/common-definitions#binary.output_licenses">output_licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_binary.plugins">plugins</a>, <a href="#java_binary.resource_strip_prefix">resource_strip_prefix</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#java_binary.runtime_deps">runtime_deps</a>, <a href="#java_binary.stamp">stamp</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="#java_binary.use_launcher">use_launcher</a>, <a href="#java_binary.use_testrunner">use_testrunner</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper shell script uses a classpath that includes, among other things, a jar file for each library on which the binary depends. When running the wrapper shell script, any nonempty <code translate="no" dir="ltr">JAVABIN</code> environment variable will take precedence over the version specified via Bazel's <code translate="no" dir="ltr">--java_runtime_version</code> flag. </p> <p> The wrapper script accepts several unique flags. Refer to <code translate="no" dir="ltr">java_stub_template.txt</code> for a list of configurable flags and environment variables accepted by the wrapper. </p> <h4 id="java_binary_implicit_outputs" data-text="Implicit output targets" tabindex="-1">Implicit output targets</h4> <ul> <li><code translate="no" dir="ltr"><var translate="no">name</var>.jar</code>: A Java archive, containing the class files and other resources corresponding to the binary's direct dependencies.</li> <li><code translate="no" dir="ltr"><var translate="no">name</var>-src.jar</code>: An archive containing the sources ("source jar").</li> <li><code translate="no" dir="ltr"><var translate="no">name</var>_deploy.jar</code>: A Java archive suitable for deployment (only built if explicitly requested). <p> Building the <code translate="no" dir="ltr"><<var translate="no">name</var>>_deploy.jar</code> target for your rule creates a self-contained jar file with a manifest that allows it to be run with the <code translate="no" dir="ltr">java -jar</code> command or with the wrapper script's <code translate="no" dir="ltr">--singlejar</code> option. Using the wrapper script is preferred to <code translate="no" dir="ltr">java -jar</code> because it also passes the <a href="#java_binary-jvm_flags">JVM flags</a> and the options to load native libraries. </p> <p> The deploy jar contains all the classes that would be found by a classloader that searched the classpath from the binary's wrapper script from beginning to end. It also contains the native libraries needed for dependencies. These are automatically loaded into the JVM at runtime. </p> <p>If your target specifies a <a href="#java_binary.launcher">launcher</a> attribute, then instead of being a normal JAR file, the _deploy.jar will be a native binary. This will contain the launcher plus any native (C++) dependencies of your rule, all linked into a static binary. The actual jar file's bytes will be appended to that native binary, creating a single binary blob containing both the executable and the Java code. You can execute the resulting jar file directly like you would execute any native binary.</p> </li> <li><code translate="no" dir="ltr"><var translate="no">name</var>_deploy-src.jar</code>: An archive containing the sources collected from the transitive closure of the target. These will match the classes in the <code translate="no" dir="ltr">deploy.jar</code> except where jars have no matching source jar.</li> </ul> <p> It is good practice to use the name of the source file that is the main entry point of the application (minus the extension). For example, if your entry point is called <code translate="no" dir="ltr">Main.java</code>, then your name could be <code translate="no" dir="ltr">Main</code>. </p> <p> A <code translate="no" dir="ltr">deps</code> attribute is not allowed in a <code translate="no" dir="ltr">java_binary</code> rule without <a href="#java_binary-srcs"><code translate="no" dir="ltr">srcs</code></a>; such a rule requires a <a href="#java_binary-main_class"><code translate="no" dir="ltr">main_class</code></a> provided by <a href="#java_binary-runtime_deps"><code translate="no" dir="ltr">runtime_deps</code></a>. </p> <p>The following code snippet illustrates a common mistake:</p> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_binary( name = "DontDoThis", srcs = [ <var translate="no">...</var>, <code class="deprecated" translate="no" dir="ltr">"GeneratedJavaFile.java"</code>, # a generated .java file ], deps = [<code class="deprecated" translate="no" dir="ltr">":generating_rule",</code>], # rule that generates that file ) </code> </pre></devsite-code> <p>Do this instead:</p> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_binary( name = "DoThisInstead", srcs = [ <var translate="no">...</var>, ":generating_rule", ], ) </code> </pre></devsite-code> <h3 id="java_binary_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_binary.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_binary.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries to be linked in to the target. See general comments about <code translate="no" dir="ltr">deps</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. </td> </tr> <tr> <td id="java_binary.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below. <p> Source files of type <code translate="no" dir="ltr">.java</code> are compiled. In case of generated <code translate="no" dir="ltr">.java</code> files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the <code translate="no" dir="ltr">outs</code> of the generating rule. You should not list the generating rule in <code translate="no" dir="ltr">deps</code> because it is a no-op. </p> <p> Source files of type <code translate="no" dir="ltr">.srcjar</code> are unpacked and compiled. (This is useful if you need to generate a set of <code translate="no" dir="ltr">.java</code> files with a genrule.) </p> <p> Rules: if the rule (typically <code translate="no" dir="ltr">genrule</code> or <code translate="no" dir="ltr">filegroup</code>) generates any of the files listed above, they will be used the same way as described for source files. </p> <p> This argument is almost always required, except if a <a href="#java_binary.main_class"><code translate="no" dir="ltr">main_class</code></a> attribute specifies a class on the runtime classpath or you specify the <code translate="no" dir="ltr">runtime_deps</code> argument. </p> </td> </tr> <tr> <td id="java_binary.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. </td> </tr> <tr> <td id="java_binary.resources"> <code translate="no" dir="ltr">resources</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> A list of data files to include in a Java jar. <p> Resources may be source files or generated files. </p> <p> If resources are specified, they will be bundled in the jar along with the usual <code translate="no" dir="ltr">.class</code> files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">standard directory layout</a>, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <code translate="no" dir="ltr"><workspace root>/x/java/y/java/z</code>, the path of the resource will be <code translate="no" dir="ltr">y/java/z</code>. This heuristic cannot be overridden, however, the <code translate="no" dir="ltr">resource_strip_prefix</code> attribute can be used to specify a specific alternative directory for resource files. </td> </tr> <tr> <td id="java_binary.add_exports"> <code translate="no" dir="ltr">add_exports</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-exports= flags. </td> </tr> <tr> <td id="java_binary.add_opens"> <code translate="no" dir="ltr">add_opens</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to reflectively access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-opens= flags. </td> </tr> <tr> <td id="java_binary.bootclasspath"> <code translate="no" dir="ltr">bootclasspath</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Restricted API, do not use! </td> </tr> <tr> <td id="java_binary.classpath_resources"> <code translate="no" dir="ltr">classpath_resources</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> <em class="harmful">DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY)</em> <p> A list of resources that must be located at the root of the java tree. This attribute's only purpose is to support third-party libraries that require that their resources be found on the classpath as exactly <code translate="no" dir="ltr">"myconfig.xml"</code>. It is only allowed on binaries and not libraries, due to the danger of namespace conflicts. </p> </td> </tr> <tr> <td id="java_binary.create_executable"> <code translate="no" dir="ltr">create_executable</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Deprecated, use <code translate="no" dir="ltr">java_single_jar</code> instead. </td> </tr> <tr> <td id="java_binary.deploy_env"> <code translate="no" dir="ltr">deploy_env</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> A list of other <code translate="no" dir="ltr">java_binary</code> targets which represent the deployment environment for this binary. Set this attribute when building a plugin which will be loaded by another <code translate="no" dir="ltr">java_binary</code>.<br/> Setting this attribute excludes all dependencies from the runtime classpath (and the deploy jar) of this binary that are shared between this binary and the targets specified in <code translate="no" dir="ltr">deploy_env</code>. </td> </tr> <tr> <td id="java_binary.deploy_manifest_lines"> <code translate="no" dir="ltr">deploy_manifest_lines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> A list of lines to add to the <code translate="no" dir="ltr">META-INF/manifest.mf</code> file generated for the <code translate="no" dir="ltr">*_deploy.jar</code> target. The contents of this attribute are <em>not</em> subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution. </td> </tr> <tr> <td id="java_binary.javacopts"> <code translate="no" dir="ltr">javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Extra compiler options for this binary. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p>These compiler options are passed to javac after the global compiler options.</p> </td> </tr> <tr> <td id="java_binary.jvm_flags"> <code translate="no" dir="ltr">jvm_flags</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> A list of flags to embed in the wrapper script generated for running this binary. Subject to <a href="/reference/be/make-variables#location">$(location)</a> and <a href="/reference/be/make-variables">"Make variable"</a> substitution, and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p>The wrapper script for a Java binary includes a CLASSPATH definition (to find all the dependent jars) and invokes the right Java interpreter. The command line generated by the wrapper script includes the name of the main class followed by a <code translate="no" dir="ltr">"$@"</code> so you can pass along other arguments after the classname. However, arguments intended for parsing by the JVM must be specified <i>before</i> the classname on the command line. The contents of <code translate="no" dir="ltr">jvm_flags</code> are added to the wrapper script before the classname is listed.</p> <p>Note that this attribute has <em>no effect</em> on <code translate="no" dir="ltr">*_deploy.jar</code> outputs.</p> </td> </tr> <tr> <td id="java_binary.launcher"> <code translate="no" dir="ltr">launcher</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Specify a binary that will be used to run your Java program instead of the normal <code translate="no" dir="ltr">bin/java</code> program included with the JDK. The target must be a <code translate="no" dir="ltr">cc_binary</code>. Any <code translate="no" dir="ltr">cc_binary</code> that implements the <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html"> Java Invocation API</a> can be specified as a value for this attribute. <p>By default, Bazel will use the normal JDK launcher (bin/java or java.exe).</p> <p>The related <a href="/docs/user-manual#flag--java_launcher"><code translate="no" dir="ltr"> --java_launcher</code></a> Bazel flag affects only those <code translate="no" dir="ltr">java_binary</code> and <code translate="no" dir="ltr">java_test</code> targets that have <i>not</i> specified a <code translate="no" dir="ltr">launcher</code> attribute.</p> <p>Note that your native (C++, SWIG, JNI) dependencies will be built differently depending on whether you are using the JDK launcher or another launcher:</p> <ul> <li>If you are using the normal JDK launcher (the default), native dependencies are built as a shared library named <code translate="no" dir="ltr">{name}_nativedeps.so</code>, where <code translate="no" dir="ltr">{name}</code> is the <code translate="no" dir="ltr">name</code> attribute of this java_binary rule. Unused code is <em>not</em> removed by the linker in this configuration.</li> <li>If you are using any other launcher, native (C++) dependencies are statically linked into a binary named <code translate="no" dir="ltr">{name}_nativedeps</code>, where <code translate="no" dir="ltr">{name}</code> is the <code translate="no" dir="ltr">name</code> attribute of this java_binary rule. In this case, the linker will remove any code it thinks is unused from the resulting binary, which means any C++ code accessed only via JNI may not be linked in unless that <code translate="no" dir="ltr">cc_library</code> target specifies <code translate="no" dir="ltr">alwayslink = True</code>.</li> </ul> <p>When using any launcher other than the default JDK launcher, the format of the <code translate="no" dir="ltr">*_deploy.jar</code> output changes. See the main <a href="#java_binary">java_binary</a> docs for details.</p> </td> </tr> <tr> <td id="java_binary.main_class"> <code translate="no" dir="ltr">main_class</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Name of class with <code translate="no" dir="ltr">main()</code> method to use as entry point. If a rule uses this option, it does not need a <code translate="no" dir="ltr">srcs=[...]</code> list. Thus, with this attribute one can make an executable from a Java library that already contains one or more <code translate="no" dir="ltr">main()</code> methods. <p> The value of this attribute is a class name, not a source file. The class must be available at runtime: it may be compiled by this rule (from <code translate="no" dir="ltr">srcs</code>) or provided by direct or transitive dependencies (through <code translate="no" dir="ltr">runtime_deps</code> or <code translate="no" dir="ltr">deps</code>). If the class is unavailable, the binary will fail at runtime; there is no build-time check. </p> </td> </tr> <tr> <td id="java_binary.neverlink"> <code translate="no" dir="ltr">neverlink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> </td> </tr> <tr> <td id="java_binary.plugins"> <code translate="no" dir="ltr">plugins</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Java compiler plugins to run at compile-time. Every <code translate="no" dir="ltr">java_plugin</code> specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use <code translate="no" dir="ltr"><a href="#java_library.exported_plugins">exported_plugins</a></code>. Resources generated by the plugin will be included in the resulting jar of this rule. </td> </tr> <tr> <td id="java_binary.resource_strip_prefix"> <code translate="no" dir="ltr">resource_strip_prefix</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The path prefix to strip from Java resources. <p> If specified, this path prefix is stripped from every file in the <code translate="no" dir="ltr">resources</code> attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at <code translate="no" dir="ltr">stuff/java/foo/bar/a.txt</code> will be located at <code translate="no" dir="ltr">foo/bar/a.txt</code>. </p> </td> </tr> <tr> <td id="java_binary.runtime_deps"> <code translate="no" dir="ltr">runtime_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Libraries to make available to the final binary or test at runtime only. Like ordinary <code translate="no" dir="ltr">deps</code>, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. Dependencies needed only at runtime should be listed here. Dependency-analysis tools should ignore targets that appear in both <code translate="no" dir="ltr">runtime_deps</code> and <code translate="no" dir="ltr">deps</code>. </td> </tr> <tr> <td id="java_binary.stamp"> <code translate="no" dir="ltr">stamp</code> </td> <td> <p>Integer; default is <code translate="no" dir="ltr">-1</code></p> Whether to encode build information into the binary. Possible values: <ul> <li> <code translate="no" dir="ltr">stamp = 1</code>: Always stamp the build information into the binary, even in <a href="/docs/user-manual#flag--stamp"><code translate="no" dir="ltr">--nostamp</code></a> builds. <b>This setting should be avoided</b>, since it potentially kills remote caching for the binary and any downstream actions that depend on it. </li> <li> <code translate="no" dir="ltr">stamp = 0</code>: Always replace build information by constant values. This gives good build result caching. </li> <li> <code translate="no" dir="ltr">stamp = -1</code>: Embedding of build information is controlled by the <a href="/docs/user-manual#flag--stamp"><code translate="no" dir="ltr">--[no]stamp</code></a> flag. </li> </ul> <p>Stamped binaries are <em>not</em> rebuilt unless their dependencies change.</p> </td> </tr> <tr> <td id="java_binary.use_launcher"> <code translate="no" dir="ltr">use_launcher</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Whether the binary should use a custom launcher. <p>If this attribute is set to false, the <a href="/reference/be/java#java_binary.launcher">launcher</a> attribute and the related <a href="/docs/user-manual#flag--java_launcher"><code translate="no" dir="ltr">--java_launcher</code></a> flag will be ignored for this target. </td> </tr> <tr> <td id="java_binary.use_testrunner"> <code translate="no" dir="ltr">use_testrunner</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Use the test runner (by default <code translate="no" dir="ltr">com.google.testing.junit.runner.BazelTestRunner</code>) class as the main entry point for a Java program, and provide the test class to the test runner as a value of <code translate="no" dir="ltr">bazel.test_suite</code> system property. <br/> You can use this to override the default behavior, which is to use test runner for <code translate="no" dir="ltr">java_test</code> rules, and not use it for <code translate="no" dir="ltr">java_binary</code> rules. It is unlikely you will want to do this. One use is for <code translate="no" dir="ltr">AllTest</code> rules that are invoked by another rule (to set up a database before running the tests, for example). The <code translate="no" dir="ltr">AllTest</code> rule must be declared as a <code translate="no" dir="ltr">java_binary</code>, but should still use the test runner as its main entry point. The name of a test runner class can be overridden with <code translate="no" dir="ltr">main_class</code> attribute. </td> </tr> </tbody> </table> <h2 id="java_import" data-text=" java_import " tabindex="-1"> java_import </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/bazel/rules/bazel_java_import.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_import(<a href="#java_import.name">name</a>, <a href="#java_import.deps">deps</a>, <a href="#java_import.data">data</a>, <a href="#java_import.add_exports">add_exports</a>, <a href="#java_import.add_opens">add_opens</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#java_import.constraints">constraints</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="#java_import.exports">exports</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_import.jars">jars</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#java_import.neverlink">neverlink</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_import.proguard_specs">proguard_specs</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#java_import.runtime_deps">runtime_deps</a>, <a href="#java_import.srcjar">srcjar</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> This rule allows the use of precompiled <code translate="no" dir="ltr">.jar</code> files as libraries for <code translate="no" dir="ltr"><a href="#java_library">java_library</a></code> and <code translate="no" dir="ltr">java_binary</code> rules. </p> <h4 id="java_import_examples" data-text="Examples" tabindex="-1">Examples</h4> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_import( name = "maven_model", jars = [ "maven_model/maven-aether-provider-3.2.3.jar", "maven_model/maven-model-3.2.3.jar", "maven_model/maven-model-builder-3.2.3.jar", ], ) </code> </pre></devsite-code> <h3 id="java_import_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_import.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_import.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries to be linked in to the target. See <a href="/reference/be/java#java_library.deps">java_library.deps</a>. </td> </tr> <tr> <td id="java_import.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this rule at runtime. </td> </tr> <tr> <td id="java_import.add_exports"> <code translate="no" dir="ltr">add_exports</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-exports= flags. </td> </tr> <tr> <td id="java_import.add_opens"> <code translate="no" dir="ltr">add_opens</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to reflectively access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-opens= flags. </td> </tr> <tr> <td id="java_import.constraints"> <code translate="no" dir="ltr">constraints</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Extra constraints imposed on this rule as a Java library. </td> </tr> <tr> <td id="java_import.exports"> <code translate="no" dir="ltr">exports</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Targets to make available to users of this rule. See <a href="/reference/be/java#java_library.exports">java_library.exports</a>. </td> </tr> <tr> <td id="java_import.jars"> <code translate="no" dir="ltr">jars</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; required</p> The list of JAR files provided to Java targets that depend on this target. </td> </tr> <tr> <td id="java_import.neverlink"> <code translate="no" dir="ltr">neverlink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Only use this library for compilation and not at runtime. Useful if the library will be provided by the runtime environment during execution. Examples of libraries like this are IDE APIs for IDE plug-ins or <code translate="no" dir="ltr">tools.jar</code> for anything running on a standard JDK. </td> </tr> <tr> <td id="java_import.proguard_specs"> <code translate="no" dir="ltr">proguard_specs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Files to be used as Proguard specification. These will describe the set of specifications to be used by Proguard. If specified, they will be added to any <code translate="no" dir="ltr">android_binary</code> target depending on this library. The files included here must only have idempotent rules, namely -dontnote, -dontwarn, assumenosideeffects, and rules that start with -keep. Other options can only appear in <code translate="no" dir="ltr">android_binary</code>'s proguard_specs, to ensure non-tautological merges. </td> </tr> <tr> <td id="java_import.runtime_deps"> <code translate="no" dir="ltr">runtime_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Libraries to make available to the final binary or test at runtime only. See <a href="/reference/be/java#java_library.runtime_deps">java_library.runtime_deps</a>. </td> </tr> <tr> <td id="java_import.srcjar"> <code translate="no" dir="ltr">srcjar</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> A JAR file that contains source code for the compiled JAR files. </td> </tr> </tbody> </table> <h2 id="java_library" data-text=" java_library " tabindex="-1"> java_library </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/bazel/rules/bazel_java_library.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_library(<a href="#java_library.name">name</a>, <a href="#java_library.deps">deps</a>, <a href="#java_library.srcs">srcs</a>, <a href="#java_library.data">data</a>, <a href="#java_library.resources">resources</a>, <a href="#java_library.add_exports">add_exports</a>, <a href="#java_library.add_opens">add_opens</a>, <a href="#java_library.bootclasspath">bootclasspath</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="#java_library.exported_plugins">exported_plugins</a>, <a href="#java_library.exports">exports</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_library.javabuilder_jvm_flags">javabuilder_jvm_flags</a>, <a href="#java_library.javacopts">javacopts</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#java_library.neverlink">neverlink</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_library.plugins">plugins</a>, <a href="#java_library.proguard_specs">proguard_specs</a>, <a href="#java_library.resource_strip_prefix">resource_strip_prefix</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#java_library.runtime_deps">runtime_deps</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>This rule compiles and links sources into a <code translate="no" dir="ltr">.jar</code> file.</p> <h4 id="implicit-outputs" data-text="Implicit outputs" tabindex="-1">Implicit outputs</h4> <ul> <li><code translate="no" dir="ltr">lib<var translate="no">name</var>.jar</code>: A Java archive containing the class files.</li> <li><code translate="no" dir="ltr">lib<var translate="no">name</var>-src.jar</code>: An archive containing the sources ("source jar").</li> </ul> <h3 id="java_library_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_library.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_library.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of libraries to link into this library. See general comments about <code translate="no" dir="ltr">deps</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p> The jars built by <code translate="no" dir="ltr">java_library</code> rules listed in <code translate="no" dir="ltr">deps</code> will be on the compile-time classpath of this rule. Furthermore the transitive closure of their <code translate="no" dir="ltr">deps</code>, <code translate="no" dir="ltr">runtime_deps</code> and <code translate="no" dir="ltr">exports</code> will be on the runtime classpath. </p> <p> By contrast, targets in the <code translate="no" dir="ltr">data</code> attribute are included in the runfiles but on neither the compile-time nor runtime classpath. </p> </td> </tr> <tr> <td id="java_library.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below. <p> Source files of type <code translate="no" dir="ltr">.java</code> are compiled. In case of generated <code translate="no" dir="ltr">.java</code> files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the <code translate="no" dir="ltr">outs</code> of the generating rule. You should not list the generating rule in <code translate="no" dir="ltr">deps</code> because it is a no-op. </p> <p> Source files of type <code translate="no" dir="ltr">.srcjar</code> are unpacked and compiled. (This is useful if you need to generate a set of <code translate="no" dir="ltr">.java</code> files with a genrule.) </p> <p> Rules: if the rule (typically <code translate="no" dir="ltr">genrule</code> or <code translate="no" dir="ltr">filegroup</code>) generates any of the files listed above, they will be used the same way as described for source files. </p> <p> Source files of type <code translate="no" dir="ltr">.properties</code> are treated as resources. </p> <p>All other files are ignored, as long as there is at least one file of a file type described above. Otherwise an error is raised.</p> <p> This argument is almost always required, except if you specify the <code translate="no" dir="ltr">runtime_deps</code> argument. </p> </td> </tr> <tr> <td id="java_library.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p> When building a <code translate="no" dir="ltr">java_library</code>, Bazel doesn't put these files anywhere; if the <code translate="no" dir="ltr">data</code> files are generated files then Bazel generates them. When building a test that depends on this <code translate="no" dir="ltr">java_library</code> Bazel copies or links the <code translate="no" dir="ltr">data</code> files into the runfiles area. </p> </td> </tr> <tr> <td id="java_library.resources"> <code translate="no" dir="ltr">resources</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> A list of data files to include in a Java jar. <p> Resources may be source files or generated files. </p> <p> If resources are specified, they will be bundled in the jar along with the usual <code translate="no" dir="ltr">.class</code> files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">standard directory layout</a>, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <code translate="no" dir="ltr"><workspace root>/x/java/y/java/z</code>, the path of the resource will be <code translate="no" dir="ltr">y/java/z</code>. This heuristic cannot be overridden, however, the <code translate="no" dir="ltr">resource_strip_prefix</code> attribute can be used to specify a specific alternative directory for resource files. </td> </tr> <tr> <td id="java_library.add_exports"> <code translate="no" dir="ltr">add_exports</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-exports= flags. </td> </tr> <tr> <td id="java_library.add_opens"> <code translate="no" dir="ltr">add_opens</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to reflectively access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-opens= flags. </td> </tr> <tr> <td id="java_library.bootclasspath"> <code translate="no" dir="ltr">bootclasspath</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Restricted API, do not use! </td> </tr> <tr> <td id="java_library.exported_plugins"> <code translate="no" dir="ltr">exported_plugins</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of <code translate="no" dir="ltr"><a href="#/reference/be/java.html#java_plugin">java_plugin</a></code>s (e.g. annotation processors) to export to libraries that directly depend on this library. <p> The specified list of <code translate="no" dir="ltr">java_plugin</code>s will be applied to any library which directly depends on this library, just as if that library had explicitly declared these labels in <code translate="no" dir="ltr"><a href="/reference/be/java#java_library.plugins">plugins</a></code>. </p> </td> </tr> <tr> <td id="java_library.exports"> <code translate="no" dir="ltr">exports</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Exported libraries. <p> Listing rules here will make them available to parent rules, as if the parents explicitly depended on these rules. This is not true for regular (non-exported) <code translate="no" dir="ltr">deps</code>. </p> <p> Summary: a rule <i>X</i> can access the code in <i>Y</i> if there exists a dependency path between them that begins with a <code translate="no" dir="ltr">deps</code> edge followed by zero or more <code translate="no" dir="ltr">exports</code> edges. Let's see some examples to illustrate this. </p> <p> Assume <i>A</i> depends on <i>B</i> and <i>B</i> depends on <i>C</i>. In this case C is a <em>transitive</em> dependency of A, so changing C's sources and rebuilding A will correctly rebuild everything. However A will not be able to use classes in C. To allow that, either A has to declare C in its <code translate="no" dir="ltr">deps</code>, or B can make it easier for A (and anything that may depend on A) by declaring C in its (B's) <code translate="no" dir="ltr">exports</code> attribute. </p> <p> The closure of exported libraries is available to all direct parent rules. Take a slightly different example: A depends on B, B depends on C and D, and also exports C but not D. Now A has access to C but not to D. Now, if C and D exported some libraries, C' and D' respectively, A could only access C' but not D'. </p> <p> Important: an exported rule is not a regular dependency. Sticking to the previous example, if B exports C and wants to also use C, it has to also list it in its own <code translate="no" dir="ltr">deps</code>. </p> </td> </tr> <tr> <td id="java_library.javabuilder_jvm_flags"> <code translate="no" dir="ltr">javabuilder_jvm_flags</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Restricted API, do not use! </td> </tr> <tr> <td id="java_library.javacopts"> <code translate="no" dir="ltr">javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Extra compiler options for this library. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p>These compiler options are passed to javac after the global compiler options.</p> </td> </tr> <tr> <td id="java_library.neverlink"> <code translate="no" dir="ltr">neverlink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Whether this library should only be used for compilation and not at runtime. Useful if the library will be provided by the runtime environment during execution. Examples of such libraries are the IDE APIs for IDE plug-ins or <code translate="no" dir="ltr">tools.jar</code> for anything running on a standard JDK. <p> Note that <code translate="no" dir="ltr">neverlink = True</code> does not prevent the compiler from inlining material from this library into compilation targets that depend on it, as permitted by the Java Language Specification (e.g., <code translate="no" dir="ltr">static final</code> constants of <code translate="no" dir="ltr">String</code> or of primitive types). The preferred use case is therefore when the runtime library is identical to the compilation library. </p> <p> If the runtime library differs from the compilation library then you must ensure that it differs only in places that the JLS forbids compilers to inline (and that must hold for all future versions of the JLS). </p> </td> </tr> <tr> <td id="java_library.plugins"> <code translate="no" dir="ltr">plugins</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Java compiler plugins to run at compile-time. Every <code translate="no" dir="ltr">java_plugin</code> specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use <code translate="no" dir="ltr"><a href="#java_library.exported_plugins">exported_plugins</a></code>. Resources generated by the plugin will be included in the resulting jar of this rule. </td> </tr> <tr> <td id="java_library.proguard_specs"> <code translate="no" dir="ltr">proguard_specs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Files to be used as Proguard specification. These will describe the set of specifications to be used by Proguard. If specified, they will be added to any <code translate="no" dir="ltr">android_binary</code> target depending on this library. The files included here must only have idempotent rules, namely -dontnote, -dontwarn, assumenosideeffects, and rules that start with -keep. Other options can only appear in <code translate="no" dir="ltr">android_binary</code>'s proguard_specs, to ensure non-tautological merges. </td> </tr> <tr> <td id="java_library.resource_strip_prefix"> <code translate="no" dir="ltr">resource_strip_prefix</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The path prefix to strip from Java resources. <p> If specified, this path prefix is stripped from every file in the <code translate="no" dir="ltr">resources</code> attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at <code translate="no" dir="ltr">stuff/java/foo/bar/a.txt</code> will be located at <code translate="no" dir="ltr">foo/bar/a.txt</code>. </p> </td> </tr> <tr> <td id="java_library.runtime_deps"> <code translate="no" dir="ltr">runtime_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Libraries to make available to the final binary or test at runtime only. Like ordinary <code translate="no" dir="ltr">deps</code>, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. Dependencies needed only at runtime should be listed here. Dependency-analysis tools should ignore targets that appear in both <code translate="no" dir="ltr">runtime_deps</code> and <code translate="no" dir="ltr">deps</code>. </td> </tr> </tbody> </table> <h2 id="java_test" data-text=" java_test " tabindex="-1"> java_test </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/bazel/rules/bazel_java_test.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_test(<a href="#java_test.name">name</a>, <a href="#java_test.deps">deps</a>, <a href="#java_test.srcs">srcs</a>, <a href="#java_test.data">data</a>, <a href="#java_test.resources">resources</a>, <a href="#java_test.add_exports">add_exports</a>, <a href="#java_test.add_opens">add_opens</a>, <a href="/reference/be/common-definitions#test.args">args</a>, <a href="#java_test.bootclasspath">bootclasspath</a>, <a href="#java_test.classpath_resources">classpath_resources</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#java_test.create_executable">create_executable</a>, <a href="#java_test.deploy_manifest_lines">deploy_manifest_lines</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#test.env">env</a>, <a href="/reference/be/common-definitions#test.env_inherit">env_inherit</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#test.flaky">flaky</a>, <a href="#java_test.javacopts">javacopts</a>, <a href="#java_test.jvm_flags">jvm_flags</a>, <a href="#java_test.launcher">launcher</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="/reference/be/common-definitions#test.local">local</a>, <a href="#java_test.main_class">main_class</a>, <a href="#java_test.neverlink">neverlink</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_test.plugins">plugins</a>, <a href="#java_test.resource_strip_prefix">resource_strip_prefix</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#java_test.runtime_deps">runtime_deps</a>, <a href="/reference/be/common-definitions#test.shard_count">shard_count</a>, <a href="/reference/be/common-definitions#test.size">size</a>, <a href="#java_test.stamp">stamp</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="#java_test.test_class">test_class</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#test.timeout">timeout</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="#java_test.use_launcher">use_launcher</a>, <a href="#java_test.use_testrunner">use_testrunner</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> A <code translate="no" dir="ltr">java_test()</code> rule compiles a Java test. A test is a binary wrapper around your test code. The test runner's main method is invoked instead of the main class being compiled. </p> <h4 id="java_test_implicit_outputs" data-text="Implicit output targets" tabindex="-1">Implicit output targets</h4> <ul> <li><code translate="no" dir="ltr"><var translate="no">name</var>.jar</code>: A Java archive.</li> <li><code translate="no" dir="ltr"><var translate="no">name</var>_deploy.jar</code>: A Java archive suitable for deployment. (Only built if explicitly requested.) See the description of the <code translate="no" dir="ltr"><var translate="no">name</var>_deploy.jar</code> output from <a href="#java_binary">java_binary</a> for more details.</li> </ul> <p> See the section on <code translate="no" dir="ltr">java_binary()</code> arguments. This rule also supports all <a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests">attributes common to all test rules (*_test)</a>. </p> <h4 id="java_test_examples" data-text="Examples" tabindex="-1">Examples</h4> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_library( name = "tests", srcs = glob(["*.java"]), deps = [ "//java/com/foo/base:testResources", "//java/com/foo/testing/util", ], ) java_test( name = "AllTests", size = "small", runtime_deps = [ ":tests", "//util/mysql", ], ) </code> </pre></devsite-code> <h3 id="java_test_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_test.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_test.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries to be linked in to the target. See general comments about <code translate="no" dir="ltr">deps</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. </td> </tr> <tr> <td id="java_test.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below. <p> Source files of type <code translate="no" dir="ltr">.java</code> are compiled. In case of generated <code translate="no" dir="ltr">.java</code> files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the <code translate="no" dir="ltr">outs</code> of the generating rule. You should not list the generating rule in <code translate="no" dir="ltr">deps</code> because it is a no-op. </p> <p> Source files of type <code translate="no" dir="ltr">.srcjar</code> are unpacked and compiled. (This is useful if you need to generate a set of <code translate="no" dir="ltr">.java</code> files with a genrule.) </p> <p> Rules: if the rule (typically <code translate="no" dir="ltr">genrule</code> or <code translate="no" dir="ltr">filegroup</code>) generates any of the files listed above, they will be used the same way as described for source files. </p> <p> This argument is almost always required, except if a <a href="#java_binary.main_class"><code translate="no" dir="ltr">main_class</code></a> attribute specifies a class on the runtime classpath or you specify the <code translate="no" dir="ltr">runtime_deps</code> argument. </p> </td> </tr> <tr> <td id="java_test.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. </td> </tr> <tr> <td id="java_test.resources"> <code translate="no" dir="ltr">resources</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> A list of data files to include in a Java jar. <p> Resources may be source files or generated files. </p> <p> If resources are specified, they will be bundled in the jar along with the usual <code translate="no" dir="ltr">.class</code> files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">standard directory layout</a>, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <code translate="no" dir="ltr"><workspace root>/x/java/y/java/z</code>, the path of the resource will be <code translate="no" dir="ltr">y/java/z</code>. This heuristic cannot be overridden, however, the <code translate="no" dir="ltr">resource_strip_prefix</code> attribute can be used to specify a specific alternative directory for resource files. </td> </tr> <tr> <td id="java_test.add_exports"> <code translate="no" dir="ltr">add_exports</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-exports= flags. </td> </tr> <tr> <td id="java_test.add_opens"> <code translate="no" dir="ltr">add_opens</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to reflectively access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-opens= flags. </td> </tr> <tr> <td id="java_test.bootclasspath"> <code translate="no" dir="ltr">bootclasspath</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Restricted API, do not use! </td> </tr> <tr> <td id="java_test.classpath_resources"> <code translate="no" dir="ltr">classpath_resources</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> <em class="harmful">DO NOT USE THIS OPTION UNLESS THERE IS NO OTHER WAY)</em> <p> A list of resources that must be located at the root of the java tree. This attribute's only purpose is to support third-party libraries that require that their resources be found on the classpath as exactly <code translate="no" dir="ltr">"myconfig.xml"</code>. It is only allowed on binaries and not libraries, due to the danger of namespace conflicts. </p> </td> </tr> <tr> <td id="java_test.create_executable"> <code translate="no" dir="ltr">create_executable</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Deprecated, use <code translate="no" dir="ltr">java_single_jar</code> instead. </td> </tr> <tr> <td id="java_test.deploy_manifest_lines"> <code translate="no" dir="ltr">deploy_manifest_lines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> A list of lines to add to the <code translate="no" dir="ltr">META-INF/manifest.mf</code> file generated for the <code translate="no" dir="ltr">*_deploy.jar</code> target. The contents of this attribute are <em>not</em> subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution. </td> </tr> <tr> <td id="java_test.javacopts"> <code translate="no" dir="ltr">javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Extra compiler options for this binary. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p>These compiler options are passed to javac after the global compiler options.</p> </td> </tr> <tr> <td id="java_test.jvm_flags"> <code translate="no" dir="ltr">jvm_flags</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> A list of flags to embed in the wrapper script generated for running this binary. Subject to <a href="/reference/be/make-variables#location">$(location)</a> and <a href="/reference/be/make-variables">"Make variable"</a> substitution, and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p>The wrapper script for a Java binary includes a CLASSPATH definition (to find all the dependent jars) and invokes the right Java interpreter. The command line generated by the wrapper script includes the name of the main class followed by a <code translate="no" dir="ltr">"$@"</code> so you can pass along other arguments after the classname. However, arguments intended for parsing by the JVM must be specified <i>before</i> the classname on the command line. The contents of <code translate="no" dir="ltr">jvm_flags</code> are added to the wrapper script before the classname is listed.</p> <p>Note that this attribute has <em>no effect</em> on <code translate="no" dir="ltr">*_deploy.jar</code> outputs.</p> </td> </tr> <tr> <td id="java_test.launcher"> <code translate="no" dir="ltr">launcher</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Specify a binary that will be used to run your Java program instead of the normal <code translate="no" dir="ltr">bin/java</code> program included with the JDK. The target must be a <code translate="no" dir="ltr">cc_binary</code>. Any <code translate="no" dir="ltr">cc_binary</code> that implements the <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html"> Java Invocation API</a> can be specified as a value for this attribute. <p>By default, Bazel will use the normal JDK launcher (bin/java or java.exe).</p> <p>The related <a href="/docs/user-manual#flag--java_launcher"><code translate="no" dir="ltr"> --java_launcher</code></a> Bazel flag affects only those <code translate="no" dir="ltr">java_binary</code> and <code translate="no" dir="ltr">java_test</code> targets that have <i>not</i> specified a <code translate="no" dir="ltr">launcher</code> attribute.</p> <p>Note that your native (C++, SWIG, JNI) dependencies will be built differently depending on whether you are using the JDK launcher or another launcher:</p> <ul> <li>If you are using the normal JDK launcher (the default), native dependencies are built as a shared library named <code translate="no" dir="ltr">{name}_nativedeps.so</code>, where <code translate="no" dir="ltr">{name}</code> is the <code translate="no" dir="ltr">name</code> attribute of this java_binary rule. Unused code is <em>not</em> removed by the linker in this configuration.</li> <li>If you are using any other launcher, native (C++) dependencies are statically linked into a binary named <code translate="no" dir="ltr">{name}_nativedeps</code>, where <code translate="no" dir="ltr">{name}</code> is the <code translate="no" dir="ltr">name</code> attribute of this java_binary rule. In this case, the linker will remove any code it thinks is unused from the resulting binary, which means any C++ code accessed only via JNI may not be linked in unless that <code translate="no" dir="ltr">cc_library</code> target specifies <code translate="no" dir="ltr">alwayslink = True</code>.</li> </ul> <p>When using any launcher other than the default JDK launcher, the format of the <code translate="no" dir="ltr">*_deploy.jar</code> output changes. See the main <a href="#java_binary">java_binary</a> docs for details.</p> </td> </tr> <tr> <td id="java_test.main_class"> <code translate="no" dir="ltr">main_class</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Name of class with <code translate="no" dir="ltr">main()</code> method to use as entry point. If a rule uses this option, it does not need a <code translate="no" dir="ltr">srcs=[...]</code> list. Thus, with this attribute one can make an executable from a Java library that already contains one or more <code translate="no" dir="ltr">main()</code> methods. <p> The value of this attribute is a class name, not a source file. The class must be available at runtime: it may be compiled by this rule (from <code translate="no" dir="ltr">srcs</code>) or provided by direct or transitive dependencies (through <code translate="no" dir="ltr">runtime_deps</code> or <code translate="no" dir="ltr">deps</code>). If the class is unavailable, the binary will fail at runtime; there is no build-time check. </p> </td> </tr> <tr> <td id="java_test.neverlink"> <code translate="no" dir="ltr">neverlink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> </td> </tr> <tr> <td id="java_test.plugins"> <code translate="no" dir="ltr">plugins</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Java compiler plugins to run at compile-time. Every <code translate="no" dir="ltr">java_plugin</code> specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use <code translate="no" dir="ltr"><a href="#java_library.exported_plugins">exported_plugins</a></code>. Resources generated by the plugin will be included in the resulting jar of this rule. </td> </tr> <tr> <td id="java_test.resource_strip_prefix"> <code translate="no" dir="ltr">resource_strip_prefix</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The path prefix to strip from Java resources. <p> If specified, this path prefix is stripped from every file in the <code translate="no" dir="ltr">resources</code> attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at <code translate="no" dir="ltr">stuff/java/foo/bar/a.txt</code> will be located at <code translate="no" dir="ltr">foo/bar/a.txt</code>. </p> </td> </tr> <tr> <td id="java_test.runtime_deps"> <code translate="no" dir="ltr">runtime_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Libraries to make available to the final binary or test at runtime only. Like ordinary <code translate="no" dir="ltr">deps</code>, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. Dependencies needed only at runtime should be listed here. Dependency-analysis tools should ignore targets that appear in both <code translate="no" dir="ltr">runtime_deps</code> and <code translate="no" dir="ltr">deps</code>. </td> </tr> <tr> <td id="java_test.stamp"> <code translate="no" dir="ltr">stamp</code> </td> <td> <p>Integer; default is <code translate="no" dir="ltr">0</code></p> Whether to encode build information into the binary. Possible values: <ul> <li> <code translate="no" dir="ltr">stamp = 1</code>: Always stamp the build information into the binary, even in <a href="https://bazel.build/docs/user-manual#stamp"><code translate="no" dir="ltr">--nostamp</code></a> builds. <b>This setting should be avoided</b>, since it potentially kills remote caching for the binary and any downstream actions that depend on it. </li> <li> <code translate="no" dir="ltr">stamp = 0</code>: Always replace build information by constant values. This gives good build result caching. </li> <li> <code translate="no" dir="ltr">stamp = -1</code>: Embedding of build information is controlled by the <a href="https://bazel.build/docs/user-manual#stamp"><code translate="no" dir="ltr">--[no]stamp</code></a> flag. </li> </ul> <p>Stamped binaries are <em>not</em> rebuilt unless their dependencies change.</p> </td> </tr> <tr> <td id="java_test.test_class"> <code translate="no" dir="ltr">test_class</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The Java class to be loaded by the test runner.<br/> <p> By default, if this argument is not defined then the legacy mode is used and the test arguments are used instead. Set the <code translate="no" dir="ltr">--nolegacy_bazel_java_test</code> flag to not fallback on the first argument. </p> <p> This attribute specifies the name of a Java class to be run by this test. It is rare to need to set this. If this argument is omitted, it will be inferred using the target's <code translate="no" dir="ltr">name</code> and its source-root-relative path. If the test is located outside a known source root, Bazel will report an error if <code translate="no" dir="ltr">test_class</code> is unset. </p> <p> For JUnit3, the test class needs to either be a subclass of <code translate="no" dir="ltr">junit.framework.TestCase</code> or it needs to have a public static <code translate="no" dir="ltr">suite()</code> method that returns a <code translate="no" dir="ltr">junit.framework.Test</code> (or a subclass of <code translate="no" dir="ltr">Test</code>). For JUnit4, the class needs to be annotated with <code translate="no" dir="ltr">org.junit.runner.RunWith</code>. </p> <p> This attribute allows several <code translate="no" dir="ltr">java_test</code> rules to share the same <code translate="no" dir="ltr">Test</code> (<code translate="no" dir="ltr">TestCase</code>, <code translate="no" dir="ltr">TestSuite</code>, ...). Typically additional information is passed to it (e.g. via <code translate="no" dir="ltr">jvm_flags=['-Dkey=value']</code>) so that its behavior differs in each case, such as running a different subset of the tests. This attribute also enables the use of Java tests outside the <code translate="no" dir="ltr">javatests</code> tree. </p> </td> </tr> <tr> <td id="java_test.use_launcher"> <code translate="no" dir="ltr">use_launcher</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Whether the binary should use a custom launcher. <p>If this attribute is set to false, the <a href="/reference/be/java#java_binary.launcher">launcher</a> attribute and the related <a href="/docs/user-manual#flag--java_launcher"><code translate="no" dir="ltr">--java_launcher</code></a> flag will be ignored for this target. </td> </tr> <tr> <td id="java_test.use_testrunner"> <code translate="no" dir="ltr">use_testrunner</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Use the test runner (by default <code translate="no" dir="ltr">com.google.testing.junit.runner.BazelTestRunner</code>) class as the main entry point for a Java program, and provide the test class to the test runner as a value of <code translate="no" dir="ltr">bazel.test_suite</code> system property. <br/> You can use this to override the default behavior, which is to use test runner for <code translate="no" dir="ltr">java_test</code> rules, and not use it for <code translate="no" dir="ltr">java_binary</code> rules. It is unlikely you will want to do this. One use is for <code translate="no" dir="ltr">AllTest</code> rules that are invoked by another rule (to set up a database before running the tests, for example). The <code translate="no" dir="ltr">AllTest</code> rule must be declared as a <code translate="no" dir="ltr">java_binary</code>, but should still use the test runner as its main entry point. The name of a test runner class can be overridden with <code translate="no" dir="ltr">main_class</code> attribute. </td> </tr> </tbody> </table> <h2 id="java_package_configuration" data-text=" java_package_configuration " tabindex="-1"> java_package_configuration </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/common/rules/java_package_configuration.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_package_configuration(<a href="#java_package_configuration.name">name</a>, <a href="#java_package_configuration.data">data</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_package_configuration.javacopts">javacopts</a>, <a href="#java_package_configuration.output_licenses">output_licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_package_configuration.packages">packages</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#java_package_configuration.system">system</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> Configuration to apply to a set of packages. Configurations can be added to <code translate="no" dir="ltr"><a href="/reference/be/java#java_toolchain.javacopts">java_toolchain.javacopts</a></code>s. </p> <h4 id="java_package_configuration_example" data-text="Example:" tabindex="-1">Example:</h4> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_package_configuration( name = "my_configuration", packages = [":my_packages"], javacopts = ["-Werror"], ) package_group( name = "my_packages", packages = [ "//com/my/project/...", "-//com/my/project/testing/...", ], ) java_toolchain( ..., package_configuration = [ ":my_configuration", ] ) </code> </pre></devsite-code> <h3 id="java_package_configuration_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_package_configuration.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_package_configuration.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this configuration at runtime. </td> </tr> <tr> <td id="java_package_configuration.javacopts"> <code translate="no" dir="ltr">javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Java compiler flags. </td> </tr> <tr> <td id="java_package_configuration.output_licenses"> <code translate="no" dir="ltr">output_licenses</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="java_package_configuration.packages"> <code translate="no" dir="ltr">packages</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The set of <code translate="no" dir="ltr"><a href="/reference/be/functions#package_group">package_group</a></code>s the configuration should be applied to. </td> </tr> <tr> <td id="java_package_configuration.system"> <code translate="no" dir="ltr">system</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Corresponds to javac's --system flag. </td> </tr> </tbody> </table> <h2 id="java_plugin" data-text=" java_plugin " tabindex="-1"> java_plugin </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/bazel/rules/bazel_java_plugin.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_plugin(<a href="#java_plugin.name">name</a>, <a href="#java_plugin.deps">deps</a>, <a href="#java_plugin.srcs">srcs</a>, <a href="#java_plugin.data">data</a>, <a href="#java_plugin.resources">resources</a>, <a href="#java_plugin.add_exports">add_exports</a>, <a href="#java_plugin.add_opens">add_opens</a>, <a href="#java_plugin.bootclasspath">bootclasspath</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_plugin.generates_api">generates_api</a>, <a href="#java_plugin.javabuilder_jvm_flags">javabuilder_jvm_flags</a>, <a href="#java_plugin.javacopts">javacopts</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#java_plugin.neverlink">neverlink</a>, <a href="#java_plugin.output_licenses">output_licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_plugin.plugins">plugins</a>, <a href="#java_plugin.processor_class">processor_class</a>, <a href="#java_plugin.proguard_specs">proguard_specs</a>, <a href="#java_plugin.resource_strip_prefix">resource_strip_prefix</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> <code translate="no" dir="ltr">java_plugin</code> defines plugins for the Java compiler run by Bazel. The only supported kind of plugins are annotation processors. A <code translate="no" dir="ltr">java_library</code> or <code translate="no" dir="ltr">java_binary</code> rule can run plugins by depending on them via the <code translate="no" dir="ltr">plugins</code> attribute. A <code translate="no" dir="ltr">java_library</code> can also automatically export plugins to libraries that directly depend on it using <code translate="no" dir="ltr"><a href="#java_library-exported_plugins">exported_plugins</a></code>. </p> <h4 id="java_plugin_implicit_outputs" data-text="Implicit output targets" tabindex="-1">Implicit output targets</h4> <ul> <li><code translate="no" dir="ltr"><var translate="no">libname</var>.jar</code>: A Java archive.</li> </ul> <p> Arguments are identical to <a href="#java_library"><code translate="no" dir="ltr">java_library</code></a>, except for the addition of the <code translate="no" dir="ltr">processor_class</code> argument. </p> <h3 id="java_plugin_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_plugin.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_plugin.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of libraries to link into this library. See general comments about <code translate="no" dir="ltr">deps</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p> The jars built by <code translate="no" dir="ltr">java_library</code> rules listed in <code translate="no" dir="ltr">deps</code> will be on the compile-time classpath of this rule. Furthermore the transitive closure of their <code translate="no" dir="ltr">deps</code>, <code translate="no" dir="ltr">runtime_deps</code> and <code translate="no" dir="ltr">exports</code> will be on the runtime classpath. </p> <p> By contrast, targets in the <code translate="no" dir="ltr">data</code> attribute are included in the runfiles but on neither the compile-time nor runtime classpath. </p> </td> </tr> <tr> <td id="java_plugin.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of source files that are processed to create the target. This attribute is almost always required; see exceptions below. <p> Source files of type <code translate="no" dir="ltr">.java</code> are compiled. In case of generated <code translate="no" dir="ltr">.java</code> files it is generally advisable to put the generating rule's name here instead of the name of the file itself. This not only improves readability but makes the rule more resilient to future changes: if the generating rule generates different files in the future, you only need to fix one place: the <code translate="no" dir="ltr">outs</code> of the generating rule. You should not list the generating rule in <code translate="no" dir="ltr">deps</code> because it is a no-op. </p> <p> Source files of type <code translate="no" dir="ltr">.srcjar</code> are unpacked and compiled. (This is useful if you need to generate a set of <code translate="no" dir="ltr">.java</code> files with a genrule.) </p> <p> Rules: if the rule (typically <code translate="no" dir="ltr">genrule</code> or <code translate="no" dir="ltr">filegroup</code>) generates any of the files listed above, they will be used the same way as described for source files. </p> <p> Source files of type <code translate="no" dir="ltr">.properties</code> are treated as resources. </p> <p>All other files are ignored, as long as there is at least one file of a file type described above. Otherwise an error is raised.</p> <p> This argument is almost always required, except if you specify the <code translate="no" dir="ltr">runtime_deps</code> argument. </p> </td> </tr> <tr> <td id="java_plugin.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p> When building a <code translate="no" dir="ltr">java_library</code>, Bazel doesn't put these files anywhere; if the <code translate="no" dir="ltr">data</code> files are generated files then Bazel generates them. When building a test that depends on this <code translate="no" dir="ltr">java_library</code> Bazel copies or links the <code translate="no" dir="ltr">data</code> files into the runfiles area. </p> </td> </tr> <tr> <td id="java_plugin.resources"> <code translate="no" dir="ltr">resources</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> A list of data files to include in a Java jar. <p> Resources may be source files or generated files. </p> <p> If resources are specified, they will be bundled in the jar along with the usual <code translate="no" dir="ltr">.class</code> files produced by compilation. The location of the resources inside of the jar file is determined by the project structure. Bazel first looks for Maven's <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">standard directory layout</a>, (a "src" directory followed by a "resources" directory grandchild). If that is not found, Bazel then looks for the topmost directory named "java" or "javatests" (so, for example, if a resource is at <code translate="no" dir="ltr"><workspace root>/x/java/y/java/z</code>, the path of the resource will be <code translate="no" dir="ltr">y/java/z</code>. This heuristic cannot be overridden, however, the <code translate="no" dir="ltr">resource_strip_prefix</code> attribute can be used to specify a specific alternative directory for resource files. </td> </tr> <tr> <td id="java_plugin.add_exports"> <code translate="no" dir="ltr">add_exports</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-exports= flags. </td> </tr> <tr> <td id="java_plugin.add_opens"> <code translate="no" dir="ltr">add_opens</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Allow this library to reflectively access the given <code translate="no" dir="ltr">module</code> or <code translate="no" dir="ltr">package</code>. <p> This corresponds to the javac and JVM --add-opens= flags. </td> </tr> <tr> <td id="java_plugin.bootclasspath"> <code translate="no" dir="ltr">bootclasspath</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Restricted API, do not use! </td> </tr> <tr> <td id="java_plugin.generates_api"> <code translate="no" dir="ltr">generates_api</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> This attribute marks annotation processors that generate API code. <p>If a rule uses an API-generating annotation processor, other rules depending on it can refer to the generated code only if their compilation actions are scheduled after the generating rule. This attribute instructs Bazel to introduce scheduling constraints when --java_header_compilation is enabled. <p><em class="harmful">WARNING: This attribute affects build performance, use it only if necessary.</em></p> </td> </tr> <tr> <td id="java_plugin.javabuilder_jvm_flags"> <code translate="no" dir="ltr">javabuilder_jvm_flags</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Restricted API, do not use! </td> </tr> <tr> <td id="java_plugin.javacopts"> <code translate="no" dir="ltr">javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Extra compiler options for this library. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p>These compiler options are passed to javac after the global compiler options.</p> </td> </tr> <tr> <td id="java_plugin.neverlink"> <code translate="no" dir="ltr">neverlink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Whether this library should only be used for compilation and not at runtime. Useful if the library will be provided by the runtime environment during execution. Examples of such libraries are the IDE APIs for IDE plug-ins or <code translate="no" dir="ltr">tools.jar</code> for anything running on a standard JDK. <p> Note that <code translate="no" dir="ltr">neverlink = True</code> does not prevent the compiler from inlining material from this library into compilation targets that depend on it, as permitted by the Java Language Specification (e.g., <code translate="no" dir="ltr">static final</code> constants of <code translate="no" dir="ltr">String</code> or of primitive types). The preferred use case is therefore when the runtime library is identical to the compilation library. </p> <p> If the runtime library differs from the compilation library then you must ensure that it differs only in places that the JLS forbids compilers to inline (and that must hold for all future versions of the JLS). </p> </td> </tr> <tr> <td id="java_plugin.output_licenses"> <code translate="no" dir="ltr">output_licenses</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="java_plugin.plugins"> <code translate="no" dir="ltr">plugins</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Java compiler plugins to run at compile-time. Every <code translate="no" dir="ltr">java_plugin</code> specified in this attribute will be run whenever this rule is built. A library may also inherit plugins from dependencies that use <code translate="no" dir="ltr"><a href="#java_library.exported_plugins">exported_plugins</a></code>. Resources generated by the plugin will be included in the resulting jar of this rule. </td> </tr> <tr> <td id="java_plugin.processor_class"> <code translate="no" dir="ltr">processor_class</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The processor class is the fully qualified type of the class that the Java compiler should use as entry point to the annotation processor. If not specified, this rule will not contribute an annotation processor to the Java compiler's annotation processing, but its runtime classpath will still be included on the compiler's annotation processor path. (This is primarily intended for use by <a href="https://errorprone.info/docs/plugins">Error Prone plugins</a>, which are loaded from the annotation processor path using <a href="https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html"> java.util.ServiceLoader</a>.) </td> </tr> <tr> <td id="java_plugin.proguard_specs"> <code translate="no" dir="ltr">proguard_specs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Files to be used as Proguard specification. These will describe the set of specifications to be used by Proguard. If specified, they will be added to any <code translate="no" dir="ltr">android_binary</code> target depending on this library. The files included here must only have idempotent rules, namely -dontnote, -dontwarn, assumenosideeffects, and rules that start with -keep. Other options can only appear in <code translate="no" dir="ltr">android_binary</code>'s proguard_specs, to ensure non-tautological merges. </td> </tr> <tr> <td id="java_plugin.resource_strip_prefix"> <code translate="no" dir="ltr">resource_strip_prefix</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The path prefix to strip from Java resources. <p> If specified, this path prefix is stripped from every file in the <code translate="no" dir="ltr">resources</code> attribute. It is an error for a resource file not to be under this directory. If not specified (the default), the path of resource file is determined according to the same logic as the Java package of source files. For example, a source file at <code translate="no" dir="ltr">stuff/java/foo/bar/a.txt</code> will be located at <code translate="no" dir="ltr">foo/bar/a.txt</code>. </p> </td> </tr> </tbody> </table> <h2 id="java_runtime" data-text=" java_runtime " tabindex="-1"> java_runtime </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/common/rules/java_runtime.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_runtime(<a href="#java_runtime.name">name</a>, <a href="#java_runtime.srcs">srcs</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#java_runtime.default_cds">default_cds</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_runtime.hermetic_srcs">hermetic_srcs</a>, <a href="#java_runtime.hermetic_static_libs">hermetic_static_libs</a>, <a href="#java_runtime.java">java</a>, <a href="#java_runtime.java_home">java_home</a>, <a href="#java_runtime.lib_ct_sym">lib_ct_sym</a>, <a href="#java_runtime.lib_modules">lib_modules</a>, <a href="#java_runtime.output_licenses">output_licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="#java_runtime.version">version</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> Specifies the configuration for a Java runtime. </p> <h4 id="java_runtime_example" data-text="Example:" tabindex="-1">Example:</h4> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_runtime( name = "jdk-9-ea+153", srcs = glob(["jdk9-ea+153/**"]), java_home = "jdk9-ea+153", ) </code> </pre></devsite-code> <h3 id="java_runtime_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_runtime.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_runtime.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> All files in the runtime. </td> </tr> <tr> <td id="java_runtime.default_cds"> <code translate="no" dir="ltr">default_cds</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Default CDS archive for hermetic <code translate="no" dir="ltr">java_runtime</code>. When hermetic is enabled for a <code translate="no" dir="ltr">java_binary</code> target the <code translate="no" dir="ltr">java_runtime</code> default CDS is packaged in the hermetic deploy JAR. </td> </tr> <tr> <td id="java_runtime.hermetic_srcs"> <code translate="no" dir="ltr">hermetic_srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Files in the runtime needed for hermetic deployments. </td> </tr> <tr> <td id="java_runtime.hermetic_static_libs"> <code translate="no" dir="ltr">hermetic_static_libs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The libraries that are statically linked with the launcher for hermetic deployments </td> </tr> <tr> <td id="java_runtime.java"> <code translate="no" dir="ltr">java</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The path to the java executable. </td> </tr> <tr> <td id="java_runtime.java_home"> <code translate="no" dir="ltr">java_home</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The path to the root of the runtime. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution. If this path is absolute, the rule denotes a non-hermetic Java runtime with a well-known path. In that case, the <code translate="no" dir="ltr">srcs</code> and <code translate="no" dir="ltr">java</code> attributes must be empty. </td> </tr> <tr> <td id="java_runtime.lib_ct_sym"> <code translate="no" dir="ltr">lib_ct_sym</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The lib/ct.sym file needed for compilation with <code translate="no" dir="ltr">--release</code>. If not specified and there is exactly one file in <code translate="no" dir="ltr">srcs</code> whose path ends with <code translate="no" dir="ltr">/lib/ct.sym</code>, that file is used. </td> </tr> <tr> <td id="java_runtime.lib_modules"> <code translate="no" dir="ltr">lib_modules</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The lib/modules file needed for hermetic deployments. </td> </tr> <tr> <td id="java_runtime.output_licenses"> <code translate="no" dir="ltr">output_licenses</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="java_runtime.version"> <code translate="no" dir="ltr">version</code> </td> <td> <p>Integer; default is <code translate="no" dir="ltr">0</code></p> The feature version of the Java runtime. I.e., the integer returned by <code translate="no" dir="ltr">Runtime.version().feature()</code>. </td> </tr> </tbody> </table> <h2 id="java_single_jar" data-text=" java_single_jar " tabindex="-1"> java_single_jar </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/java_single_jar.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_single_jar(<a href="#java_single_jar.name">name</a>, <a href="#java_single_jar.deps">deps</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#java_single_jar.compress">compress</a>, <a href="#java_single_jar.deploy_env">deploy_env</a>, <a href="#java_single_jar.deploy_manifest_lines">deploy_manifest_lines</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="#java_single_jar.exclude_build_data">exclude_build_data</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_single_jar.multi_release">multi_release</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> Collects Java dependencies and jar files into a single jar `java_single_jar` collects Java dependencies and jar files into a single jar. This is similar to java_binary with everything related to executables disabled, and provides an alternative to the java_binary "deploy jar hack". ## Example ```skylark load("//tools/build_defs/java_single_jar:java_single_jar.bzl", "java_single_jar") java_single_jar( name = "my_single_jar", deps = [ "//java/com/google/foo", "//java/com/google/bar", ], ) ``` Outputs: {name}.jar: A single jar containing all of the inputs. <h3 id="java_single_jar_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_single_jar.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_single_jar.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The Java targets (including java_import and java_library) to collect transitive dependencies from. Runtime dependencies are collected via deps, exports, and runtime_deps. Resources are also collected. Native cc_library or java_wrap_cc dependencies are not. </td> </tr> <tr> <td id="java_single_jar.compress"> <code translate="no" dir="ltr">compress</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">"preserve"</code></p> Whether to always deflate ("yes"), always store ("no"), or pass through unmodified ("preserve"). The default is "preserve", and is the most efficient option -- no extra work is done to inflate or deflate. </td> </tr> <tr> <td id="java_single_jar.deploy_env"> <code translate="no" dir="ltr">deploy_env</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> A list of `java_binary` or `java_single_jar` targets which represent the deployment environment for this binary. Set this attribute when building a plugin which will be loaded by another `java_binary`. `deploy_env` dependencies are excluded from the jar built by this rule. </td> </tr> <tr> <td id="java_single_jar.deploy_manifest_lines"> <code translate="no" dir="ltr">deploy_manifest_lines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> A list of lines to add to the <code translate="no" dir="ltr">META-INF/manifest.mf</code> file. </td> </tr> <tr> <td id="java_single_jar.exclude_build_data"> <code translate="no" dir="ltr">exclude_build_data</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Whether to omit the build-data.properties file generated by default. </td> </tr> <tr> <td id="java_single_jar.multi_release"> <code translate="no" dir="ltr">multi_release</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Whether to enable Multi-Release output jars. </td> </tr> </tbody> </table> <h2 id="java_toolchain" data-text=" java_toolchain " tabindex="-1"> java_toolchain </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/rules_java/blob/master/java/common/rules/java_toolchain.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>java_toolchain(<a href="#java_toolchain.name">name</a>, <a href="#java_toolchain.android_lint_data">android_lint_data</a>, <a href="#java_toolchain.android_lint_jvm_opts">android_lint_jvm_opts</a>, <a href="#java_toolchain.android_lint_opts">android_lint_opts</a>, <a href="#java_toolchain.android_lint_package_configuration">android_lint_package_configuration</a>, <a href="#java_toolchain.android_lint_runner">android_lint_runner</a>, <a href="#java_toolchain.bootclasspath">bootclasspath</a>, <a href="#java_toolchain.compatible_javacopts">compatible_javacopts</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="#java_toolchain.deps_checker">deps_checker</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#java_toolchain.forcibly_disable_header_compilation">forcibly_disable_header_compilation</a>, <a href="#java_toolchain.genclass">genclass</a>, <a href="#java_toolchain.header_compiler">header_compiler</a>, <a href="#java_toolchain.header_compiler_builtin_processors">header_compiler_builtin_processors</a>, <a href="#java_toolchain.header_compiler_direct">header_compiler_direct</a>, <a href="#java_toolchain.ijar">ijar</a>, <a href="#java_toolchain.jacocorunner">jacocorunner</a>, <a href="#java_toolchain.java_runtime">java_runtime</a>, <a href="#java_toolchain.javabuilder">javabuilder</a>, <a href="#java_toolchain.javabuilder_data">javabuilder_data</a>, <a href="#java_toolchain.javabuilder_jvm_opts">javabuilder_jvm_opts</a>, <a href="#java_toolchain.javac_supports_multiplex_workers">javac_supports_multiplex_workers</a>, <a href="#java_toolchain.javac_supports_worker_cancellation">javac_supports_worker_cancellation</a>, <a href="#java_toolchain.javac_supports_worker_multiplex_sandboxing">javac_supports_worker_multiplex_sandboxing</a>, <a href="#java_toolchain.javac_supports_workers">javac_supports_workers</a>, <a href="#java_toolchain.javacopts">javacopts</a>, <a href="#java_toolchain.jspecify_implicit_deps">jspecify_implicit_deps</a>, <a href="#java_toolchain.jspecify_javacopts">jspecify_javacopts</a>, <a href="#java_toolchain.jspecify_packages">jspecify_packages</a>, <a href="#java_toolchain.jspecify_processor">jspecify_processor</a>, <a href="#java_toolchain.jspecify_processor_class">jspecify_processor_class</a>, <a href="#java_toolchain.jspecify_stubs">jspecify_stubs</a>, <a href="#java_toolchain.jvm_opts">jvm_opts</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#java_toolchain.misc">misc</a>, <a href="#java_toolchain.oneversion">oneversion</a>, <a href="#java_toolchain.oneversion_allowlist">oneversion_allowlist</a>, <a href="#java_toolchain.oneversion_allowlist_for_tests">oneversion_allowlist_for_tests</a>, <a href="#java_toolchain.oneversion_whitelist">oneversion_whitelist</a>, <a href="#java_toolchain.package_configuration">package_configuration</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#java_toolchain.proguard_allowlister">proguard_allowlister</a>, <a href="#java_toolchain.reduced_classpath_incompatible_processors">reduced_classpath_incompatible_processors</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#java_toolchain.singlejar">singlejar</a>, <a href="#java_toolchain.source_version">source_version</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="#java_toolchain.target_version">target_version</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="#java_toolchain.timezone_data">timezone_data</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="#java_toolchain.tools">tools</a>, <a href="#java_toolchain.turbine_data">turbine_data</a>, <a href="#java_toolchain.turbine_jvm_opts">turbine_jvm_opts</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>, <a href="#java_toolchain.xlint">xlint</a>)</pre></devsite-code> <p> Specifies the configuration for the Java compiler. Which toolchain to be used can be changed through the --java_toolchain argument. Normally you should not write those kind of rules unless you want to tune your Java compiler. </p> <h4 id="examples" data-text="Examples" tabindex="-1">Examples</h4> <p>A simple example would be: </p> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> <code class="lang-starlark" translate="no" dir="ltr"> java_toolchain( name = "toolchain", source_version = "7", target_version = "7", bootclasspath = ["//tools/jdk:bootclasspath"], xlint = [ "classfile", "divzero", "empty", "options", "path" ], javacopts = [ "-g" ], javabuilder = ":JavaBuilder_deploy.jar", ) </code> </pre></devsite-code> <h3 id="java_toolchain_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="java_toolchain.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="java_toolchain.android_lint_data"> <code translate="no" dir="ltr">android_lint_data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Labels of tools available for label-expansion in android_lint_jvm_opts. </td> </tr> <tr> <td id="java_toolchain.android_lint_jvm_opts"> <code translate="no" dir="ltr">android_lint_jvm_opts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of arguments for the JVM when invoking Android Lint. </td> </tr> <tr> <td id="java_toolchain.android_lint_opts"> <code translate="no" dir="ltr">android_lint_opts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of Android Lint arguments. </td> </tr> <tr> <td id="java_toolchain.android_lint_package_configuration"> <code translate="no" dir="ltr">android_lint_package_configuration</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Android Lint Configuration that should be applied to the specified package groups. </td> </tr> <tr> <td id="java_toolchain.android_lint_runner"> <code translate="no" dir="ltr">android_lint_runner</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the Android Lint runner, if any. </td> </tr> <tr> <td id="java_toolchain.bootclasspath"> <code translate="no" dir="ltr">bootclasspath</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The Java target bootclasspath entries. Corresponds to javac's -bootclasspath flag. </td> </tr> <tr> <td id="java_toolchain.compatible_javacopts"> <code translate="no" dir="ltr">compatible_javacopts</code> </td> <td> <p>null; default is <code translate="no" dir="ltr">{}</code></p> Internal API, do not use! </td> </tr> <tr> <td id="java_toolchain.deps_checker"> <code translate="no" dir="ltr">deps_checker</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the ImportDepsChecker deploy jar. </td> </tr> <tr> <td id="java_toolchain.forcibly_disable_header_compilation"> <code translate="no" dir="ltr">forcibly_disable_header_compilation</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Overrides --java_header_compilation to disable header compilation on platforms that do not support it, e.g. JDK 7 Bazel. </td> </tr> <tr> <td id="java_toolchain.genclass"> <code translate="no" dir="ltr">genclass</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the GenClass deploy jar. </td> </tr> <tr> <td id="java_toolchain.header_compiler"> <code translate="no" dir="ltr">header_compiler</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the header compiler. Required if --java_header_compilation is enabled. </td> </tr> <tr> <td id="java_toolchain.header_compiler_builtin_processors"> <code translate="no" dir="ltr">header_compiler_builtin_processors</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Internal API, do not use! </td> </tr> <tr> <td id="java_toolchain.header_compiler_direct"> <code translate="no" dir="ltr">header_compiler_direct</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Optional label of the header compiler to use for direct classpath actions that do not include any API-generating annotation processors. <p>This tool does not support annotation processing. </td> </tr> <tr> <td id="java_toolchain.ijar"> <code translate="no" dir="ltr">ijar</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the ijar executable. </td> </tr> <tr> <td id="java_toolchain.jacocorunner"> <code translate="no" dir="ltr">jacocorunner</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the JacocoCoverageRunner deploy jar. </td> </tr> <tr> <td id="java_toolchain.java_runtime"> <code translate="no" dir="ltr">java_runtime</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The java_runtime to use with this toolchain. It defaults to java_runtime in execution configuration. </td> </tr> <tr> <td id="java_toolchain.javabuilder"> <code translate="no" dir="ltr">javabuilder</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the JavaBuilder deploy jar. </td> </tr> <tr> <td id="java_toolchain.javabuilder_data"> <code translate="no" dir="ltr">javabuilder_data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Labels of data available for label-expansion in javabuilder_jvm_opts. </td> </tr> <tr> <td id="java_toolchain.javabuilder_jvm_opts"> <code translate="no" dir="ltr">javabuilder_jvm_opts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of arguments for the JVM when invoking JavaBuilder. </td> </tr> <tr> <td id="java_toolchain.javac_supports_multiplex_workers"> <code translate="no" dir="ltr">javac_supports_multiplex_workers</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> True if JavaBuilder supports running as a multiplex persistent worker, false if it doesn't. </td> </tr> <tr> <td id="java_toolchain.javac_supports_worker_cancellation"> <code translate="no" dir="ltr">javac_supports_worker_cancellation</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> True if JavaBuilder supports cancellation of persistent workers, false if it doesn't. </td> </tr> <tr> <td id="java_toolchain.javac_supports_worker_multiplex_sandboxing"> <code translate="no" dir="ltr">javac_supports_worker_multiplex_sandboxing</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> True if JavaBuilder supports running as a multiplex persistent worker with sandboxing, false if it doesn't. </td> </tr> <tr> <td id="java_toolchain.javac_supports_workers"> <code translate="no" dir="ltr">javac_supports_workers</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> True if JavaBuilder supports running as a persistent worker, false if it doesn't. </td> </tr> <tr> <td id="java_toolchain.javacopts"> <code translate="no" dir="ltr">javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of extra arguments for the Java compiler. Please refer to the Java compiler documentation for the extensive list of possible Java compiler flags. </td> </tr> <tr> <td id="java_toolchain.jspecify_implicit_deps"> <code translate="no" dir="ltr">jspecify_implicit_deps</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Experimental, do not use! </td> </tr> <tr> <td id="java_toolchain.jspecify_javacopts"> <code translate="no" dir="ltr">jspecify_javacopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Experimental, do not use! </td> </tr> <tr> <td id="java_toolchain.jspecify_packages"> <code translate="no" dir="ltr">jspecify_packages</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Experimental, do not use! </td> </tr> <tr> <td id="java_toolchain.jspecify_processor"> <code translate="no" dir="ltr">jspecify_processor</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Experimental, do not use! </td> </tr> <tr> <td id="java_toolchain.jspecify_processor_class"> <code translate="no" dir="ltr">jspecify_processor_class</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Experimental, do not use! </td> </tr> <tr> <td id="java_toolchain.jspecify_stubs"> <code translate="no" dir="ltr">jspecify_stubs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Experimental, do not use! </td> </tr> <tr> <td id="java_toolchain.jvm_opts"> <code translate="no" dir="ltr">jvm_opts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of arguments for the JVM when invoking the Java compiler. Please refer to the Java virtual machine documentation for the extensive list of possible flags for this option. </td> </tr> <tr> <td id="java_toolchain.misc" class="deprecated"> <code translate="no" dir="ltr">misc</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Deprecated: use javacopts instead </td> </tr> <tr> <td id="java_toolchain.oneversion"> <code translate="no" dir="ltr">oneversion</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the one-version enforcement binary. </td> </tr> <tr> <td id="java_toolchain.oneversion_allowlist"> <code translate="no" dir="ltr">oneversion_allowlist</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the one-version allowlist. </td> </tr> <tr> <td id="java_toolchain.oneversion_allowlist_for_tests"> <code translate="no" dir="ltr">oneversion_allowlist_for_tests</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the one-version allowlist for tests. </td> </tr> <tr> <td id="java_toolchain.oneversion_whitelist" class="deprecated"> <code translate="no" dir="ltr">oneversion_whitelist</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Deprecated: use oneversion_allowlist instead </td> </tr> <tr> <td id="java_toolchain.package_configuration"> <code translate="no" dir="ltr">package_configuration</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Configuration that should be applied to the specified package groups. </td> </tr> <tr> <td id="java_toolchain.proguard_allowlister"> <code translate="no" dir="ltr">proguard_allowlister</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">"@bazel_tools//tools/jdk:proguard_whitelister"</code></p> Label of the Proguard allowlister. </td> </tr> <tr> <td id="java_toolchain.reduced_classpath_incompatible_processors"> <code translate="no" dir="ltr">reduced_classpath_incompatible_processors</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Internal API, do not use! </td> </tr> <tr> <td id="java_toolchain.singlejar"> <code translate="no" dir="ltr">singlejar</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the SingleJar deploy jar. </td> </tr> <tr> <td id="java_toolchain.source_version"> <code translate="no" dir="ltr">source_version</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The Java source version (e.g., '6' or '7'). It specifies which set of code structures are allowed in the Java source code. </td> </tr> <tr> <td id="java_toolchain.target_version"> <code translate="no" dir="ltr">target_version</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The Java target version (e.g., '6' or '7'). It specifies for which Java runtime the class should be build. </td> </tr> <tr> <td id="java_toolchain.timezone_data"> <code translate="no" dir="ltr">timezone_data</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of a resource jar containing timezone data. If set, the timezone data is added as an implicitly runtime dependency of all java_binary rules. </td> </tr> <tr> <td id="java_toolchain.tools"> <code translate="no" dir="ltr">tools</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Labels of tools available for label-expansion in jvm_opts. </td> </tr> <tr> <td id="java_toolchain.turbine_data"> <code translate="no" dir="ltr">turbine_data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Labels of data available for label-expansion in turbine_jvm_opts. </td> </tr> <tr> <td id="java_toolchain.turbine_jvm_opts"> <code translate="no" dir="ltr">turbine_jvm_opts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of arguments for the JVM when invoking turbine. </td> </tr> <tr> <td id="java_toolchain.xlint"> <code translate="no" dir="ltr">xlint</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> The list of warning to add or removes from default list. Precedes it with a dash to removes it. Please see the Javac documentation on the -Xlint options for more information. </td> </tr> </tbody> </table> <!-- Generated footer --> </div> <devsite-thumb-rating position="footer"> </devsite-thumb-rating> <devsite-feedback position="footer" project-name="Bazel" product-id="5052038" bucket="https-bazel-build" context="" version="t-devsite-webserver-20250325-r00-rc03.468100743126793331" data-label="Send Feedback Button" track-type="feedback" track-name="sendFeedbackLink" track-metadata-position="footer" class="nocontent" project-icon="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/touchicon-180.png" > <button> Send feedback </button> </devsite-feedback> <div class="devsite-floating-action-buttons"> </div> </article> <devsite-content-footer class="nocontent"> <p>Except as otherwise noted, the content of this page is licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 License</a>, and code samples are licensed under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 License</a>. For details, see the <a href="https://developers.google.com/site-policies">Google Developers Site Policies</a>. Java is a registered trademark of Oracle and/or its affiliates.</p> <p>Last updated 2025-03-29 UTC.</p> </devsite-content-footer> <devsite-notification > </devsite-notification> <div class="devsite-content-data"> <template class="devsite-thumb-rating-feedback"> <devsite-feedback position="thumb-rating" project-name="Bazel" product-id="5052038" bucket="https-bazel-build" context="" version="t-devsite-webserver-20250325-r00-rc03.468100743126793331" data-label="Send Feedback Button" track-type="feedback" track-name="sendFeedbackLink" track-metadata-position="thumb-rating" class="nocontent" project-icon="https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/touchicon-180.png" > <button> Need to tell us more? </button> </devsite-feedback> </template> <template class="devsite-content-data-template"> [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-29 UTC."],[],[]] </template> </div> </devsite-content> </main> <devsite-footer-promos class="devsite-footer"> </devsite-footer-promos> <devsite-footer-linkboxes class="devsite-footer"> <nav class="devsite-footer-linkboxes nocontent" aria-label="Footer links"> <ul class="devsite-footer-linkboxes-list"> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">About</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="/community/users" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Who's using Bazel </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/contribute/" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > Contribute </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/contribute/contribution-policy" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Governance model </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/release" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > Release model </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/brand" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 5)" > Brand guidelines </a> </li> </ul> </li> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">Stay connected</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="//blog.bazel.build" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Blog </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//github.com/bazelbuild/bazel" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > GitHub </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//twitter.com/bazelbuild" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Twitter </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//youtube.com/user/googleOSPO" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > YouTube </a> </li> </ul> </li> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">Support</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="/help" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Support </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//github.com/bazelbuild/bazel/issues" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > Issue tracker </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//slack.bazel.build" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Slack </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//stackoverflow.com/questions/tagged/bazel" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > Stack Overflow </a> </li> </ul> </li> </ul> </nav> </devsite-footer-linkboxes> <devsite-footer-utility class="devsite-footer"> <div class="devsite-footer-utility nocontent"> <nav class="devsite-footer-utility-links" aria-label="Utility links"> <ul class="devsite-footer-utility-list"> <li class="devsite-footer-utility-item "> <a class="devsite-footer-utility-link gc-analytics-event" href="//policies.google.com/terms" data-category="Site-Wide Custom Events" data-label="Footer Terms link" > Terms </a> </li> <li class="devsite-footer-utility-item "> <a class="devsite-footer-utility-link gc-analytics-event" href="//policies.google.com/privacy" data-category="Site-Wide Custom Events" data-label="Footer Privacy link" > Privacy </a> </li> <li class="devsite-footer-utility-item glue-cookie-notification-bar-control"> <a class="devsite-footer-utility-link gc-analytics-event" href="#" data-category="Site-Wide Custom Events" data-label="Footer Manage cookies link" aria-hidden="true" > Manage cookies </a> </li> </ul> <devsite-language-selector> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" >English</a> </li> <li role="presentation"> <a role="menuitem" lang="es_419" >Español – América Latina</a> </li> <li role="presentation"> <a role="menuitem" lang="fr" >Français</a> </li> <li role="presentation"> <a role="menuitem" lang="id" >Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="it" >Italiano</a> </li> <li role="presentation"> <a role="menuitem" lang="pl" >Polski</a> </li> <li role="presentation"> <a role="menuitem" lang="pt_br" >Português – Brasil</a> </li> <li role="presentation"> <a role="menuitem" lang="vi" >Tiếng Việt</a> </li> <li role="presentation"> <a role="menuitem" lang="tr" >Türkçe</a> </li> <li role="presentation"> <a role="menuitem" lang="ru" >Русский</a> </li> <li role="presentation"> <a role="menuitem" lang="he" >עברית</a> </li> <li role="presentation"> <a role="menuitem" lang="ar" >العربيّة</a> </li> <li role="presentation"> <a role="menuitem" lang="fa" >فارسی</a> </li> <li role="presentation"> <a role="menuitem" lang="hi" >हिंदी</a> </li> <li role="presentation"> <a role="menuitem" lang="bn" >বাংলা</a> </li> <li role="presentation"> <a role="menuitem" lang="th" >ภาษาไทย</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_cn" >中文 – 简体</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_tw" >中文 – 繁體</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" >日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" >한국어</a> </li> </ul> </devsite-language-selector> </nav> </div> </devsite-footer-utility> <devsite-panel></devsite-panel> </section></section> <devsite-sitemask></devsite-sitemask> <devsite-snackbar></devsite-snackbar> <devsite-tooltip ></devsite-tooltip> <devsite-heading-link></devsite-heading-link> <devsite-analytics> <script type="application/json" analytics>[{"dimensions": {"dimension2": false, "dimension3": "en", "dimension5": false, "dimension1": "Signed out", "dimension4": "en"}, "gaid": "UA-61082125-3", "metrics": {}, "purpose": 0}]</script> <script type="application/json" tag-management>{"at": "True", "ga4": [{"id": "G-GBZW986TQ3", "purpose": 0}], "ga4p": [{"id": "G-GBZW986TQ3", "purpose": 0}], "gtm": [], "parameters": {"internalUser": "False", "language": {"machineTranslated": "False", "requested": "en", "served": "en"}, "pageType": "article", "projectName": "Bazel", "signedIn": "False", "tenant": "bazel", "recommendations": {"sourcePage": "", "sourceType": 0, "sourceRank": 0, "sourceIdenticalDescriptions": 0, "sourceTitleWords": 0, "sourceDescriptionWords": 0, "experiment": ""}, "experiment": {"ids": ""}}}</script> </devsite-analytics> <devsite-badger></devsite-badger> <script nonce="28ASYEGSlPjVNz6VfERlvy/xFgyZWm"> (function(d,e,v,s,i,t,E){d['GoogleDevelopersObject']=i; t=e.createElement(v);t.async=1;t.src=s;E=e.getElementsByTagName(v)[0]; E.parentNode.insertBefore(t,E);})(window, document, 'script', 'https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/js/app_loader.js', '[40,"en",null,"/js/devsite_app_module.js","https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9","https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel","https://bazel-dot-devsite-v2-prod-3p.appspot.com",null,null,["/_pwa/bazel/manifest.json","https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/images/video-placeholder.svg","https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/favicon-prod.png","https://www.gstatic.com/devrel-devsite/prod/vd31e3ed8994e05c7f2cd0cf68a402ca7902bb92b6ec0977d7ef2a1c699fae3f9/bazel/images/lockup.svg","https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap"],1,null,[1,6,8,12,14,17,21,25,50,52,63,70,75,76,80,87,91,92,93,97,98,100,101,102,103,104,105,107,108,109,110,112,113,117,118,120,122,124,125,126,127,129,130,131,132,133,134,135,136,138,140,141,147,148,149,151,152,156,157,158,159,161,163,164,168,169,170,179,180,182,183,186,191,193,196],"AIzaSyCNm9YxQumEXwGJgTDjxoxXK6m1F-9720Q","AIzaSyCc76DZePGtoyUjqKrLdsMGk_ry7sljLbY","bazel.build","AIzaSyB9bqgQ2t11WJsOX8qNsCQ6U-w91mmqF-I","AIzaSyAdYnStPdzjcJJtQ0mvIaeaMKj7_t6J_Fg",null,null,null,["Cloud__enable_llm_concierge_chat","DevPro__enable_firebase_workspaces_card","Profiles__enable_complete_playlist_endpoint","Search__enable_page_map","MiscFeatureFlags__enable_variable_operator_index_yaml","Search__enable_dynamic_content_confidential_banner","EngEduTelemetry__enable_engedu_telemetry","Profiles__enable_dashboard_curated_recommendations","Cloud__enable_cloudx_experiment_ids","MiscFeatureFlags__enable_view_transitions","MiscFeatureFlags__enable_explain_this_code","MiscFeatureFlags__enable_variable_operator","MiscFeatureFlags__emergency_css","SignIn__enable_oauth_multi_account_support","Concierge__enable_pushui","DevPro__enable_devpro_offers","MiscFeatureFlags__gdp_dashboard_reskin_enabled","Cloud__enable_cloudx_ping","Experiments__reqs_query_experiments","Cloud__enable_legacy_calculator_redirect","DevPro__enable_code_assist","Profiles__enable_profile_collections","CloudShell__cloud_shell_button","Analytics__enable_clearcut_logging","TpcFeatures__enable_unmirrored_page_left_nav","Profiles__enable_awarding_url","Profiles__enable_stripe_subscription_management","Profiles__enable_recognition_badges","Cloud__enable_cloud_dlp_service","MiscFeatureFlags__enable_framebox_badge_methods","CloudShell__cloud_code_overflow_menu","Cloud__enable_cloud_shell","DevPro__enable_developer_subscriptions","MiscFeatureFlags__enable_firebase_utm","MiscFeatureFlags__developers_footer_image","Profiles__enable_page_saving","Cloud__enable_cloud_facet_chat","MiscFeatureFlags__enable_project_variables","DevPro__enable_vertex_credit_card","Cloud__enable_cloud_shell_fte_user_flow","TpcFeatures__enable_mirror_tenant_redirects","OnSwitch__enable","BookNav__enable_tenant_cache_key","Profiles__enable_completecodelab_endpoint","Profiles__enable_join_program_group_endpoint","MiscFeatureFlags__developers_footer_dark_image","Profiles__enable_release_notes_notifications","DevPro__enable_google_one_card","Profiles__enable_completequiz_endpoint","Cloud__enable_free_trial_server_call","SignIn__enable_refresh_access_tokens","Concierge__enable_actions_menu","Profiles__enable_purchase_prompts","DevPro__enable_enterprise","Profiles__enable_public_developer_profiles","Search__enable_ai_eligibility_checks","Profiles__enable_developer_profiles_callout","Search__enable_suggestions_from_borg","SignIn__enable_auto_login_multi_account","DevPro__enable_cloud_innovators_plus","Profiles__require_profile_eligibility_for_signin"],null,null,"AIzaSyA58TaKli1DculwmAmbpzLVGuWc8eCQgQc","https://developerscontentserving-pa.googleapis.com","AIzaSyDWBU60w0P9hEkr29kkksYs8Z7gvZ8u_wc","https://developerscontentsearch-pa.googleapis.com",2,4,null,"https://developerprofiles-pa.googleapis.com",[40,"bazel","Bazel","bazel.build",null,"bazel-dot-devsite-v2-prod-3p.appspot.com",null,null,[null,1,null,null,null,null,null,null,null,null,null,[1],null,null,null,null,null,null,[1],null,null,null,null,[1,1,1],[1,1,null,1,1]],null,[56,null,null,null,null,null,"/images/lockup.svg",null,null,null,null,1,null,null,null,null,null,null,null,null,null,1,null,null,null,null,[]],[],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[6,7,1,18,20,22,23,29,37,39,40,43],null,[[],[1,1]],[[["UA-61082125-3"],["UA-61082125-4"],null,null,["UA-61082125-5"],null,null,[["G-GBZW986TQ3"],null,null,[["G-GBZW986TQ3",1]]],[["UA-61082125-3",1]],null,[["UA-61082125-5",1]],null,1],[[4,5],[1,1],[2,2],[3,4],[5,8]]],null,4],null,null,1,null,"https://developerscontentinsights-pa.googleapis.com","AIzaSyC11xEGtFhkmSh_iF6l_itbxnFz2GrIBOg","AIzaSyAXJ10nRF73mmdSDINgkCNX5bbd2KPcWm8"]') </script> <devsite-a11y-announce></devsite-a11y-announce> </body> </html>