Google Ads API Bill of Materials (BOM) نسخههای وابستگی را مدیریت میکند تا از تداخل وابستگی با کتابخانههایی مانند 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>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 نسخه ۵.۰ و بالاتر از وارد کردن 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 نسخه مشخصی ندارند، قابل حل است.