רשימת החומרים (BOM) של Google Ads API מנהלת גרסאות של תלויות כדי למנוע התנגשויות בין תלויות לבין ספריות כמו Guava ו-GAX, שגם הן נמצאות בשימוש במסגרות אחרות. ה-BOM מבטיח שתשתמשו בגרסאות המדויקות של התלויות האלה שנבדקו עם ספריית הלקוח של Google Ads.
זו הדרך המומלצת להשתמש בארטיפקטים של ספריית הלקוח.
הגדרת Maven {#maven-configuration}
התלות ב-Maven היא:
<!-- 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>41.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 היא:
// Import the Bill of Materials (BOM).
implementation platform('com.google.api-ads:google-ads-bom:41.1.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:
implementation 'com.google.guava:guava' // NO VERSION SPECIFIED
אם לא מציינים את הגרסה, ה-BOM מנהל אותה, וכך אפשר למנוע בעיות שנגרמות מגרסאות לא תואמות של יחסי תלות. אינדיקטורים נפוצים של קונפליקטים של תלות כוללים NoSuchMethodError או ClassNotFoundException, שאפשר לפתור אותם בדרך כלל על ידי וידוא שלכל התלויות שמנוהלות על ידי BOM לא צוינה גרסה.