تُدير قائمة المواد (BOM) في 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>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
يتيح الإصدار 5.0 من Gradle والإصدارات الأحدث استيراد قائمة مواد (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")
تحديد التبعيات التي تغطيها قائمة المواد
يتضمّن قائمة مواد إنشاء Google Ads API إدارة الإصدارات للعديد من المكتبات الشائعة، مثل Guava وProtobuf وGAX وgRPC. لتجنُّب
التعارضات المحتملة في التبعيات، يجب عدم تحديد إصدار عند
تحديد التبعيات التي تغطيها قائمة المواد. تدير قائمة المواد تلقائيًا إصدارات هذه المكتبات، ما يضمن التوافق.
على سبيل المثال، للإعلان عن اعتمادية 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، ويمكن غالبًا حلّها من خلال التأكّد من عدم تحديد أي إصدار لجميع التبعيات التي تتم إدارتها باستخدام قائمة المواد.