רשימת החומרים (BOM) של Google Ads API מנהלת גרסאות של תלויות כדי למנוע התנגשויות בין תלויות לבין ספריות כמו 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
רשימת רכיבים (BOM) של Google Ads API כוללת ניהול גרסאות של כמה ספריות נפוצות, כמו 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
אם לא מציינים את הגרסה, ה-BOM מנהל אותה, וכך אפשר למנוע בעיות שנגרמות בגלל גרסאות לא תואמות של יחסי תלות. אינדיקטורים נפוצים להתנגשויות בין יחסי תלות כוללים את NoSuchMethodError או ClassNotFoundException, ולעיתים קרובות אפשר לפתור אותם על ידי וידוא שלכל יחסי התלות שמנוהלים על ידי BOM לא צוינה גרסה.