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

Bill of Materials (BOM) ของ Google Ads API จะจัดการเวอร์ชันทรัพยากร Dependency เพื่อหลีกเลี่ยงความขัดแย้งของทรัพยากร Dependency กับไลบรารีต่างๆ เช่น Guava และ GAX ซึ่งเฟรมเวิร์กอื่นๆ ก็ใช้ด้วย BOM จะช่วยให้คุณใช้ทรัพยากร Dependency เวอร์ชันที่ผ่านการทดสอบกับไลบรารีของไคลเอ็นต์ Google Ads แล้ว

นี่คือวิธีที่แนะนำในการใช้ Artifact ของไลบรารีของไคลเอ็นต์

การกำหนดค่า Maven {#maven-configuration}

ทรัพยากร Dependency ของ 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>44.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

ทรัพยากร Dependency ของ Gradle มีดังนี้

// Import the Bill of Materials (BOM).
implementation platform('com.google.api-ads:google-ads-bom:44.0.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 ที่ BOM ครอบคลุม เพื่อหลีกเลี่ยงความขัดแย้งที่อาจเกิดขึ้นกับทรัพยากร Dependency BOM จะจัดการเวอร์ชันของไลบรารีเหล่านี้โดยอัตโนมัติเพื่อให้มั่นใจว่าเข้ากันได้

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