ใบเรียกเก็บเงิน

รายการวัสดุ (BOM) ของ Google Ads API จะจัดการเวอร์ชันการอ้างอิง เพื่อหลีกเลี่ยงความขัดแย้งของการอ้างอิงกับไลบรารี เช่น 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>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

Gradle 5.0 ขึ้นไปรองรับการนำเข้า 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")

การประกาศทรัพยากร Dependency ที่ครอบคลุมโดย BOM

BOM ของ Google Ads API มีการจัดการเวอร์ชันสำหรับไลบรารีทั่วไปหลายรายการ เช่น Guava, Protobuf, GAX และ gRPC หากต้องการหลีกเลี่ยง การขัดแย้งของทรัพยากร Dependency ที่อาจเกิดขึ้น คุณต้องไม่ระบุเวอร์ชันเมื่อ ประกาศทรัพยากร Dependency ที่ BOM ครอบคลุม BOM จะจัดการเวอร์ชันของไลบรารีเหล่านี้โดยอัตโนมัติเพื่อให้มั่นใจว่าเข้ากันได้

เช่น หากต้องการประกาศทรัพยากร Dependency 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 จัดการเวอร์ชันได้ ซึ่งจะช่วยป้องกันปัญหาที่เกิดจากเวอร์ชันทรัพยากร Dependency ที่ไม่เข้ากัน ตัวบ่งชี้ที่พบบ่อยของความขัดแย้งของทรัพยากร Dependency ได้แก่ NoSuchMethodError หรือ ClassNotFoundException ซึ่งมักแก้ไขได้โดยตรวจสอบว่าทรัพยากร Dependency ทั้งหมดที่จัดการโดย BOM ไม่ได้ระบุเวอร์ชัน