รายการวัสดุ (BOM) ของ Google Ads API
จัดการเวอร์ชันการอ้างอิงเพื่อหลีกเลี่ยงความขัดแย้งของการอ้างอิงกับไลบรารี เช่น
Guava และ GAX ซึ่งเฟรมเวิร์กอื่นๆ ก็ใช้เช่นกัน BOM ช่วยให้มั่นใจได้ว่า
คุณใช้การขึ้นต่อกันเหล่านี้ในเวอร์ชันที่แน่นอนซึ่งผ่านการทดสอบกับ
ไลบรารีไคลเอ็นต์ของ Google Ads แล้ว
นี่คือวิธีที่แนะนำในการใช้สิ่งประดิษฐ์ของไลบรารีของไคลเอ็นต์
การกำหนดค่า 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>41.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
Dependency ของ Gradle คือ
// Import the Bill of Materials (BOM).
implementation platform('com.google.api-ads:google-ads-bom:41.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 คุณต้องไม่ระบุเวอร์ชันเมื่อประกาศการอ้างอิงที่ BOM ครอบคลุมเพื่อหลีกเลี่ยงความขัดแย้งของการอ้างอิงที่อาจเกิดขึ้น
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 ได้แก่ NoSuchMethodError หรือ ClassNotFoundException ซึ่งมักแก้ไขได้โดยตรวจสอบว่าทรัพยากร Dependency ทั้งหมดที่ BOM จัดการไม่มีการระบุเวอร์ชัน