درخت محصول

Google Ads API Bill of Materials (BOM) نسخه‌های وابستگی را مدیریت می‌کند تا از تداخل وابستگی با کتابخانه‌هایی مانند Guava و GAX که توسط چارچوب‌های دیگر نیز استفاده می‌شوند، جلوگیری کند. BOM تضمین می‌کند که شما دقیقاً از نسخه‌هایی از این وابستگی‌ها استفاده می‌کنید که با کتابخانه کارخواه Google Ads آزمایش شده‌اند.

این روش توصیه‌شده برای مصرف کردن مصنوعات کتابخانه کلاینت است.

پیکربندی Maven

BOM را به <dependencyManagement> اضافه کنید و google-ads را در فایل pom.xml خود اعلام کنید:

<!-- Import the Bill of Materials (BOM) to ensure you're using compatible
     versions of all google-ads libraries. -->
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.api-ads</groupId>
      <artifactId>google-ads-bom</artifactId>
      <version>48.0.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<!-- Add the google-ads dependency, without a version. The version is
     managed by the BOM. -->
<dependency>
  <groupId>com.google.api-ads</groupId>
  <artifactId>google-ads</artifactId>
</dependency>

پیکربندی Gradle

‫Gradle 5.0 و نسخه‌های جدیدتر از وارد کردن BOM به‌صورت بومی بااستفاده از platform() پشتیبانی می‌کنند.

در Groovy DSL (build.gradle):

// Import the Bill of Materials (BOM).
implementation platform('com.google.api-ads:google-ads-bom:48.0.0')

// Add the google-ads dependency, without a version.
implementation 'com.google.api-ads:google-ads'

در Kotlin DSL (build.gradle.kts):

// Import the Bill of Materials (BOM).
implementation(platform("com.google.api-ads:google-ads-bom:48.0.0"))

// Add the google-ads dependency, without a version.
implementation("com.google.api-ads:google-ads")

اعلام وابستگی‌های تحت پوشش BOM

Google Ads API BOM شامل مدیریت نسخه برای چندین کتابخانه رایج، مانند Guava،‏ Protobuf،‏ GAX، و gRPC است. برای جلوگیری از تداخل‌های احتمالی وابستگی، هنگام اعلام وابستگی‌هایی که «فهرست مواد» پوشش می‌دهد، نباید نسخه مشخص کنید. ‫BOM به‌طور خودکار نسخه‌های این کتابخانه‌ها را مدیریت می‌کند و سازگاری را تضمین می‌کند.

برای مثال، برای اعلام وابستگی Guava در Maven، از موارد زیر استفاده کنید:

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <!-- NO VERSION SPECIFIED -->
</dependency>

در Gradle Groovy DSL‏ (build.gradle):

implementation 'com.google.guava:guava' // NO VERSION SPECIFIED

در Gradle Kotlin DSL (build.gradle.kts):

implementation("com.google.guava:guava") // NO VERSION SPECIFIED

با حذف نسخه، به «فهرست مواد اولیه» اجازه می‌دهید آن را مدیریت کند که به جلوگیری از مشکلات ناشی از نسخه‌های وابستگی ناسازگار کمک می‌کند. نشانگرهای رایج تعارض‌های وابستگی شامل NoSuchMethodError یا ClassNotFoundException می‌شود که اغلب با اطمینان از اینکه همه وابستگی‌های مدیریت‌شده با BOM نسخه مشخصی ندارند، قابل‌حل است.