CINXE.COM
Migrating from Maven to 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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel/css/app.css"> <link rel="shortcut icon" href="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel/images/favicon-prod.png"> <link rel="apple-touch-icon" href="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel/images/touchicon-180.png"><link rel="canonical" href="https://bazel.build/versions/6.5.0/migrate/maven"><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/versions/6.5.0/migrate/maven" /><link rel="alternate" hreflang="x-default" href="https://bazel.build/versions/6.5.0/migrate/maven" /><link rel="alternate" hreflang="zh-Hans" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=zh-cn" /><link rel="alternate" hreflang="zh-Hant" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=zh-tw" /><link rel="alternate" hreflang="hi" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=hi" /><link rel="alternate" hreflang="id" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=id" /><link rel="alternate" hreflang="ja" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=ja" /><link rel="alternate" hreflang="ko" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=ko" /><link rel="alternate" hreflang="pt-BR" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=pt-br" /><link rel="alternate" hreflang="es-419" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=es-419" /><link rel="alternate" hreflang="th" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=th" /><link rel="alternate" hreflang="tr" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=tr" /><link rel="alternate" hreflang="vi" href="https://bazel.build/versions/6.5.0/migrate/maven?hl=vi" /><link rel="alternate" hreflang="en-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven" /><link rel="alternate" hreflang="x-default" href="https://bazel.google.cn/versions/6.5.0/migrate/maven" /><link rel="alternate" hreflang="zh-Hans-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=zh-cn" /><link rel="alternate" hreflang="zh-Hant-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=zh-tw" /><link rel="alternate" hreflang="hi-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=hi" /><link rel="alternate" hreflang="id-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=id" /><link rel="alternate" hreflang="ja-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=ja" /><link rel="alternate" hreflang="ko-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=ko" /><link rel="alternate" hreflang="pt-BR-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=pt-br" /><link rel="alternate" hreflang="es-419-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=es-419" /><link rel="alternate" hreflang="th-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=th" /><link rel="alternate" hreflang="tr-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=tr" /><link rel="alternate" hreflang="vi-cn" href="https://bazel.google.cn/versions/6.5.0/migrate/maven?hl=vi" /><title>Migrating from Maven to Bazel</title> <meta property="og:title" content="Migrating from Maven to Bazel"><meta property="og:url" content="https://bazel.build/versions/6.5.0/migrate/maven"><meta property="og:locale" content="en"><script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "headline": "Migrating from Maven to Bazel" } </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> <section class="devsite-wrapper"> <devsite-cookie-notification-bar></devsite-cookie-notification-bar><devsite-header role="banner"> <div class="devsite-header--inner nocontent"> <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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/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/versions/6.5.0/about" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/about" class="devsite-tabs-content gc-analytics-event " 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/versions/6.5.0/start" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/start" class="devsite-tabs-content gc-analytics-event " 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 class="devsite-active"> <a href="https://bazel.build/versions/6.5.0/docs" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/docs" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - user guide" track-metadata-module="primary nav" aria-label="User guide, selected" data-category="Site-Wide Custom Events" data-label="Tab: User guide" track-name="user guide" > User guide </a> </tab> <tab > <a href="https://bazel.build/versions/6.5.0/reference" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/reference" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - reference" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Reference" track-name="reference" > Reference </a> </tab> <tab > <a href="https://bazel.build/versions/6.5.0/extending" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/extending" class="devsite-tabs-content gc-analytics-event " 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/versions/6.5.0/community" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/community" class="devsite-tabs-content gc-analytics-event " 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" track-metadata-eventdetail="https://bazel.build/versions" class="devsite-tabs-content gc-analytics-event " 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> <a href="#" role="button" aria-haspopup="true" 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"></a> <div class="devsite-tabs-dropdown" 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/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.3.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.3.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.3 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.2.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.2.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.2 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.1.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.1.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.1 </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="id" >Indonesia</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="hi" >हिंदी</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 </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/versions/6.5.0/docs" 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="" > Guides and tutorials for learning to use Bazel </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 > <a href="https://bazel.build/versions/6.5.0/release" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/release" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - releases" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Releases" track-name="releases" > Releases </a> </tab> <tab > <a href="https://bazel.build/versions/6.5.0/build/style-guide" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/build/style-guide" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - basics" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Basics" track-name="basics" > Basics </a> </tab> <tab > <a href="https://bazel.build/versions/6.5.0/configure/attributes" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/configure/attributes" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - advanced" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Advanced" track-name="advanced" > Advanced </a> </tab> <tab > <a href="https://bazel.build/versions/6.5.0/remote/rbe" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/remote/rbe" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - remote execution" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Remote execution" track-name="remote execution" > Remote execution </a> </tab> <tab > <a href="https://bazel.build/versions/6.5.0/tutorials/cpp-use-cases" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/tutorials/cpp-use-cases" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - tutorials" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Tutorials" track-name="tutorials" > Tutorials </a> </tab> <tab class="devsite-active"> <a href="https://bazel.build/versions/6.5.0/migrate" track-metadata-eventdetail="https://bazel.build/versions/6.5.0/migrate" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - migrate" track-metadata-module="primary nav" aria-label="Migrate, selected" data-category="Site-Wide Custom Events" data-label="Tab: Migrate" track-name="migrate" > Migrate </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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/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="/versions/6.5.0/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="/versions/6.5.0/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="/versions/6.5.0/docs" class="devsite-nav-title gc-analytics-event devsite-nav-active" 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> <ul class="devsite-nav-responsive-tabs"> <li class="devsite-nav-item"> <a href="/versions/6.5.0/release" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Releases" track-name="releases" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Releases" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Releases </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/build/style-guide" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Basics" track-name="basics" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Basics" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Basics </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/configure/attributes" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Advanced" track-name="advanced" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Advanced" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Advanced </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/remote/rbe" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Remote execution" track-name="remote execution" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Remote execution" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Remote execution </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/tutorials/cpp-use-cases" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Tutorials" track-name="tutorials" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Tutorials" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Tutorials </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/migrate" class="devsite-nav-title gc-analytics-event devsite-nav-has-children devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Migrate" track-name="migrate" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Migrate" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip menu="_book"> Migrate </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="_book"> </span> </a> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/reference" class="devsite-nav-title gc-analytics-event " 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> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0/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="/versions/6.5.0/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"><a href="/versions/6.5.0/migrate" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /versions/6.5.0/migrate" track-type="bookNav" track-name="click" track-metadata-eventdetail="/versions/6.5.0/migrate" ><span class="devsite-nav-text" tooltip>Overview</span></a></li> <li class="devsite-nav-item"><a href="/versions/6.5.0/migrate/maven" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /versions/6.5.0/migrate/maven" track-type="bookNav" track-name="click" track-metadata-eventdetail="/versions/6.5.0/migrate/maven" ><span class="devsite-nav-text" tooltip>Maven</span></a></li> <li class="devsite-nav-item"><a href="/versions/6.5.0/migrate/xcode" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /versions/6.5.0/migrate/xcode" track-type="bookNav" track-name="click" track-metadata-eventdetail="/versions/6.5.0/migrate/xcode" ><span class="devsite-nav-text" tooltip>Xcode</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/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.3.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.3" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.3 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.2.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.2" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.2 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.1.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.1" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.1 </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" 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/versions/6.5.0/docs" 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="" > User guide </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://bazel.build/versions/6.5.0/migrate" 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="" > Migrate </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-20241114-r00-rc02.464921008191574316" 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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel/images/touchicon-180.png" > <button> Send feedback </button> </devsite-feedback> <h1 class="devsite-page-title" tabindex="-1"> Migrating from Maven to Bazel </h1> <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 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 "> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/issues/new?title=%5Bbazel.build%5D+Problem+with+/versions/6.5.0/migrate/maven&template=doc_issue.yml&link=https%3A%2F%2Fbazel.build/versions/6.5.0/migrate/maven" 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/site/en/versions/6.5.0/migrate/maven.md" 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"> <a href="/migrate/maven">Nightly</a> <!-- The lines below are updated by //scripts/docs:gen_new_toc --> <!-- BEGIN_VERSION_INDICATOR --> · <a href="/versions/7.4.0/migrate/maven">7.4</a> . <a href="/versions/7.3.0/migrate/maven">7.3</a> · <a href="/versions/7.2.0/migrate/maven">7.2</a> · <a href="/versions/7.1.0/migrate/maven">7.1</a> · <a href="/versions/7.0.0/migrate/maven">7.0</a> · <strong>6.5</strong> <!-- END_VERSION_INDICATOR --> </span> <p/> <p>This page describes how to migrate from Maven to Bazel, including the prerequisites and installation steps. It describes the differences between Maven and Bazel, and provides a migration example using the Guava project.</p> <p>When migrating from any build tool to Bazel, it's best to have both build tools running in parallel until you have fully migrated your development team, CI system, and any other relevant systems. You can run Maven and Bazel in the same repository.</p> <aside class="note"><strong>Note:</strong><span> While Bazel supports downloading and publishing Maven artifacts with <a href="https://github.com/bazelbuild/rules_jvm_external" class="external">rules_jvm_external</a>, it does not directly support Maven-based plugins. Maven plugins can't be directly run by Bazel since there's no Maven compatibility layer.</span></aside> <h2 id="before-you-begin" data-text="Before you begin" tabindex="-1">Before you begin</h2> <ul> <li><a href="/versions/6.5.0/install">Install Bazel</a> if it's not yet installed.</li> <li>If you're new to Bazel, go through the tutorial <a href="/versions/6.5.0/tutorials/java">Introduction to Bazel: Build Java</a> before you start migrating. The tutorial explains Bazel's concepts, structure, and label syntax.</li> </ul> <h2 id="dif-maven-bazel" data-text="Differences between Maven and Bazel" tabindex="-1">Differences between Maven and Bazel</h2> <ul> <li>Maven uses top-level <code translate="no" dir="ltr">pom.xml</code> file(s). Bazel supports multiple build files and multiple targets per <code translate="no" dir="ltr">BUILD</code> file, allowing for builds that are more incremental than Maven's.</li> <li>Maven takes charge of steps for the deployment process. Bazel does not automate deployment.</li> <li>Bazel enables you to express dependencies between languages.</li> <li>As you add new sections to the project, with Bazel you may need to add new <code translate="no" dir="ltr">BUILD</code> files. Best practice is to add a <code translate="no" dir="ltr">BUILD</code> file to each new Java package.</li> </ul> <h2 id="migrate-maven-bazel" data-text="Migrate from Maven to Bazel" tabindex="-1">Migrate from Maven to Bazel</h2> <p>The steps below describe how to migrate your project to Bazel:</p> <ol> <li><a href="#1-build">Create the WORKSPACE file</a></li> <li><a href="#2-build">Create one BUILD file</a></li> <li><a href="#3-build">Create more BUILD files</a></li> <li><a href="#4-build">Build using Bazel</a></li> </ol> <p>Examples below come from a migration of the <a href="https://github.com/google/guava" class="external">Guava project</a> from Maven to Bazel. The Guava project used is release <code translate="no" dir="ltr">v31.1</code>. The examples using Guava do not walk through each step in the migration, but they do show the files and contents that are generated or added manually for the migration.</p> <pre class="prettyprint" translate="no" dir="ltr"><code translate="no" dir="ltr">$ git clone https://github.com/google/guava.git && cd guava $ git checkout v31.1 </code></pre> <h3 id="1-build" data-text="1. Create the WORKSPACE file" tabindex="-1">1. Create the WORKSPACE file</h3> <p>Create a file named <code translate="no" dir="ltr">WORKSPACE</code> at the root of your project. If your project has no external dependencies, the workspace file can be empty.</p> <p>If your project depends on files or packages that are not in one of the project's directories, specify these external dependencies in the workspace file. To automate the listing of external dependencies for the workspace file, use <code translate="no" dir="ltr">rules_jvm_external</code>. For instructions about using this ruleset, see <a href="https://github.com/bazelbuild/rules_jvm_external/#rules_jvm_external" class="external">the README</a>.</p> <aside class="note"><strong>Note:</strong><span> The previously recommended tool, <code translate="no" dir="ltr">generate_workspace</code>, is no longer maintained by the Bazel team.</span></aside> <h4 id="guava-1" data-text="Guava project example: external dependencies" tabindex="-1">Guava project example: external dependencies</h4> <p>You can list the external dependencies of the <a href="https://github.com/google/guava" class="external">Guava project</a> with the <a href="https://github.com/bazelbuild/rules_jvm_external" class="external"><code translate="no" dir="ltr">rules_jvm_external</code></a> ruleset.</p> <p>Add the following snippet to the <code translate="no" dir="ltr">WORKSPACE</code> file:</p> <pre class="prettyprint lang-python" translate="no" dir="ltr"><code translate="no" dir="ltr">load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") RULES_JVM_EXTERNAL_TAG = "4.3" RULES_JVM_EXTERNAL_SHA = "6274687f6fc5783b589f56a2f1ed60de3ce1f99bc4e8f9edef3de43bdf7c6e74" http_archive( name = "rules_jvm_external", sha256 = RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, ) load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( artifacts = [ "com.google.code.findbugs:jsr305:3.0.2", "com.google.errorprone:error_prone_annotations:2.11.0", "com.google.j2objc:j2objc-annotations:1.3", "org.codehaus.mojo:animal-sniffer-annotations:1.20", "org.checkerframework:checker-qual:3.12.0", ], repositories = [ "https://repo1.maven.org/maven2", ], ) </code></pre> <h3 id="2-build" data-text="2. Create one BUILD file" tabindex="-1">2. Create one BUILD file</h3> <p>Now that you have your workspace defined and external dependencies (if applicable) listed, you need to create <code translate="no" dir="ltr">BUILD</code> files to describe how your project should be built. Unlike Maven with its one <code translate="no" dir="ltr">pom.xml</code> file, Bazel can use many <code translate="no" dir="ltr">BUILD</code> files to build a project. These files specify multiple build targets, which allow Bazel to produce incremental builds.</p> <p>Add <code translate="no" dir="ltr">BUILD</code> files in stages. Start with adding one <code translate="no" dir="ltr">BUILD</code> file at the root of your project and using it to do an initial build using Bazel. Then, you refine your build by adding more <code translate="no" dir="ltr">BUILD</code> files with more granular targets.</p> <ol> <li><p>In the same directory as your <code translate="no" dir="ltr">WORKSPACE</code> file, create a text file and name it <code translate="no" dir="ltr">BUILD</code>.</p></li> <li><p>In this <code translate="no" dir="ltr">BUILD</code> file, use the appropriate rule to create one target to build your project. Here are some tips:</p> <ul> <li><p>Use the appropriate rule:</p> <ul> <li><p>To build projects with a single Maven module, use the <code translate="no" dir="ltr">java_library</code> rule as follows:</p> <pre class="prettyprint lang-python" translate="no" dir="ltr"><code translate="no" dir="ltr">java_library( name = "everything", srcs = glob(["src/main/java/**/*.java"]), resources = glob(["src/main/resources/**"]), deps = ["//:all-external-targets"], ) </code></pre></li> <li><p>To build projects with multiple Maven modules, use the <code translate="no" dir="ltr">java_library</code> rule as follows:</p> <pre class="prettyprint lang-python" translate="no" dir="ltr"><code translate="no" dir="ltr">java_library( name = "everything", srcs = glob([ "Module1/src/main/java/**/*.java", "Module2/src/main/java/**/*.java", ... ]), resources = glob([ "Module1/src/main/resources/**", "Module2/src/main/resources/**", ... ]), deps = ["//:all-external-targets"], ) </code></pre></li> <li><p>To build binaries, use the <code translate="no" dir="ltr">java_binary</code> rule:</p> <pre class="prettyprint lang-python" translate="no" dir="ltr"><code translate="no" dir="ltr">java_binary( name = "everything", srcs = glob(["src/main/java/**/*.java"]), resources = glob(["src/main/resources/**"]), deps = ["//:all-external-targets"], main_class = "com.example.Main" ) </code></pre></li> </ul></li> <li><p>Specify the attributes:</p> <ul> <li><code translate="no" dir="ltr">name</code>: Give the target a meaningful name. In the examples above, the target is called "everything."</li> <li><code translate="no" dir="ltr">srcs</code>: Use globbing to list all .java files in your project.</li> <li><code translate="no" dir="ltr">resources</code>: Use globbing to list all resources in your project.</li> <li><code translate="no" dir="ltr">deps</code>: You need to determine which external dependencies your project needs. For example, if you generated a list of external dependencies using the tool <code translate="no" dir="ltr">generate_workspace</code>, the dependencies for <code translate="no" dir="ltr">java_library</code> are the libraries listed in the <code translate="no" dir="ltr">generated_java_libraries</code> macro.</li> </ul></li> <li><p>Take a look at the <a href="#guava-2">example below of this top-level BUILD file</a> from the migration of the Guava project.</p></li> </ul></li> <li><p>Now that you have a <code translate="no" dir="ltr">BUILD</code> file at the root of your project, build your project to ensure that it works. On the command line, from your workspace directory, use <code translate="no" dir="ltr">bazel build //:everything</code> to build your project with Bazel.</p> <p>The project has now been successfully built with Bazel. You will need to add more <code translate="no" dir="ltr">BUILD</code> files to allow incremental builds of the project.</p></li> </ol> <h4 id="guava-2" data-text="Guava project example: start with one BUILD file" tabindex="-1">Guava project example: start with one BUILD file</h4> <p>When migrating the Guava project to Bazel, initially one <code translate="no" dir="ltr">BUILD</code> file is used to build the entire project. Here are the contents of this initial <code translate="no" dir="ltr">BUILD</code> file in the workspace directory:</p> <pre class="prettyprint lang-python" translate="no" dir="ltr"><code translate="no" dir="ltr">java_library( name = "everything", srcs = glob([ "guava/src/**/*.java", "futures/failureaccess/src/**/*.java", ]), deps = [ "@maven//:com_google_code_findbugs_jsr305", "@maven//:com_google_errorprone_error_prone_annotations", "@maven//:com_google_j2objc_j2objc_annotations", "@maven//:org_checkerframework_checker_qual", "@maven//:org_codehaus_mojo_animal_sniffer_annotations", ], ) </code></pre> <h3 id="3-build" data-text="3. Create more BUILD files (optional)" tabindex="-1">3. Create more BUILD files (optional)</h3> <p>Bazel does work with just one <code translate="no" dir="ltr">BUILD file</code>, as you saw after completing your first build. You should still consider breaking the build into smaller chunks by adding more <code translate="no" dir="ltr">BUILD</code> files with granular targets.</p> <p>Multiple <code translate="no" dir="ltr">BUILD</code> files with multiple targets will give the build increased granularity, allowing:</p> <ul> <li>increased incremental builds of the project,</li> <li>increased parallel execution of the build,</li> <li>better maintainability of the build for future users, and</li> <li>control over visibility of targets between packages, which can prevent issues such as libraries containing implementation details leaking into public APIs.</li> </ul> <p>Tips for adding more <code translate="no" dir="ltr">BUILD</code> files:</p> <ul> <li>You can start by adding a <code translate="no" dir="ltr">BUILD</code> file to each Java package. Start with Java packages that have the fewest dependencies and work you way up to packages with the most dependencies.</li> <li>As you add <code translate="no" dir="ltr">BUILD</code> files and specify targets, add these new targets to the <code translate="no" dir="ltr">deps</code> sections of targets that depend on them. Note that the <code translate="no" dir="ltr">glob()</code> function does not cross package boundaries, so as the number of packages grows the files matched by <code translate="no" dir="ltr">glob()</code> will shrink.</li> <li>Any time you add a <code translate="no" dir="ltr">BUILD</code> file to a <code translate="no" dir="ltr">main</code> directory, ensure that you add a <code translate="no" dir="ltr">BUILD</code> file to the corresponding <code translate="no" dir="ltr">test</code> directory.</li> <li>Take care to limit visibility properly between packages.</li> <li>To simplify troubleshooting errors in your setup of <code translate="no" dir="ltr">BUILD</code> files, ensure that the project continues to build with Bazel as you add each build file. Run <code translate="no" dir="ltr">bazel build //...</code> to ensure all of your targets still build.</li> </ul> <h3 id="4-build" data-text="4. Build using Bazel" tabindex="-1">4. Build using Bazel</h3> <p>You've been building using Bazel as you add <code translate="no" dir="ltr">BUILD</code> files to validate the setup of the build.</p> <p>When you have <code translate="no" dir="ltr">BUILD</code> files at the desired granularity, you can use Bazel to produce all of your builds.</p> </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-20241114-r00-rc02.464921008191574316" 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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/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 2024-10-22 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-20241114-r00-rc02.464921008191574316" 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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/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 2024-10-22 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="id" >Indonesia</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="hi" >हिंदी</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": {"dimension1": "Signed out", "dimension4": "en", "dimension2": false, "dimension3": "en", "dimension5": false}, "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="b3PD99tFDFmjXUZOGgUbq4r9bPmi4F"> (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/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel/js/app_loader.js', '[40,"en",null,"/js/devsite_app_module.js","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel","https://bazel-dot-devsite-v2-prod-3p.appspot.com",null,null,["/_pwa/bazel/manifest.json","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/images/video-placeholder.svg","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/bazel/images/favicon-prod.png","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/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,["Profiles__enable_completecodelab_endpoint","CloudShell__cloud_code_overflow_menu","SignIn__enable_auto_login_multi_account","Profiles__enable_page_saving","Profiles__enable_dashboard_curated_recommendations","Profiles__require_profile_eligibility_for_signin","Cloud__enable_llm_concierge_chat","Cloud__enable_cloud_shell_fte_user_flow","MiscFeatureFlags__enable_variable_operator","SignIn__enable_refresh_access_tokens","Search__enable_dynamic_content_confidential_banner","EngEduTelemetry__enable_engedu_telemetry","MiscFeatureFlags__enable_view_transitions","Profiles__enable_recognition_badges","Cloud__enable_cloudx_ping","Profiles__enable_public_developer_profiles","Search__enable_suggestions_from_borg","MiscFeatureFlags__enable_explain_this_code","Profiles__enable_release_notes_notifications","Cloud__enable_legacy_calculator_redirect","Profiles__enable_complete_playlist_endpoint","Profiles__enable_profile_collections","MiscFeatureFlags__enable_firebase_utm","Profiles__enable_awarding_url","MiscFeatureFlags__enable_project_variables","TpcFeatures__enable_mirror_tenant_redirects","Cloud__enable_cloud_shell","CloudShell__cloud_shell_button","Profiles__enable_developer_profiles_callout","SignIn__enable_oauth_multi_account_support","Search__enable_page_map","Experiments__reqs_query_experiments","MiscFeatureFlags__developers_footer_dark_image","OnSwitch__enable","Cloud__enable_cloud_dlp_service","DevPro__enable_developer_subscriptions","Cloud__enable_cloudx_experiment_ids","TpcFeatures__enable_required_headers","BookNav__enable_tenant_cache_key","MiscFeatureFlags__developers_footer_image","DevPro__enable_cloud_innovators_plus","Concierge__enable_pushui","Cloud__enable_free_trial_server_call","Analytics__enable_clearcut_logging","MiscFeatureFlags__emergency_css","Search__enable_ai_eligibility_checks","Cloud__enable_cloud_facet_chat"],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],[[3,4],[5,8],[2,2],[4,5],[1,1]]],null,4]]') </script> <devsite-a11y-announce></devsite-a11y-announce> </body> </html>