تتولّى قائمة مواد Google Ads API إدارة إصدارات التبعيات لتجنُّب تعارض التبعيات مع المكتبات، مثل Guava وGAX، التي تستخدمها أيضًا أُطر أخرى. تضمن قائمة BOM استخدام الإصدارات المحدّدة من هذه التبعيات التي تم اختبارها مع مكتبة برامج العميل في "إعلانات Google".
هذه هي الطريقة المقترَحة لاستخدام عناصر مكتبة العميل.
إعدادات 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>46.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
يتيح الإصدار 5.0 من Gradle والإصدارات الأحدث استيراد قائمة BOM بشكلٍ أصلي باستخدام platform().
في Groovy DSL (build.gradle):
// Import the Bill of Materials (BOM).
implementation platform('com.google.api-ads:google-ads-bom:46.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:46.1.0"))
// Add the google-ads dependency, without a version.
implementation("com.google.api-ads:google-ads")
تحديد العناصر التابعة التي يغطيها بيان المواد
يتضمّن قائمة مواد إنشاء Google Ads API إدارة الإصدارات للعديد من المكتبات الشائعة، مثل 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، ويمكن غالبًا حلّها من خلال التأكّد من عدم تحديد أي إصدار لجميع التبعيات المُدارة بواسطة قائمة المواد.