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