רשימת החומרים (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>47.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:47.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:47.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 לא צוין גרסה.