2025 年 9 月 18 日,星期四
我們很高興宣布推出 Google Ads API Java 用戶端程式庫的 google-ads-bom,現已隨附於 google-ads 用戶端程式庫 v40.0.0。這項新的物料清單 (BOM) 可大幅簡化依附元件管理作業,並提升 Google Ads API 整合的穩定性。
什麼是 BOM?
BOM 是一種建構階段工具,提供集中、權威的「規則手冊」,用於管理依附元件版本。匯入 BOM 後,專案就會使用與 Google Ads 用戶端建構及測試時完全相同的相容依附元件版本。這有助於避免與 Guava 和 GAX 等程式庫發生依附元件衝突,這些程式庫也用於許多其他架構。
如何將 google-ads-bom 納入程式碼
如要運用 google-ads-bom 的優點,請將其匯入建構檔案的 <dependencyManagement> 區段 (例如 Maven 的 pom.xml 或 Gradle 的 build.gradle)。接著,您應在 <dependencies> 部分省略 google-ads 依附元件的版本規格。
如何在 Maven 專案中加入 BOM:
<!-- Import the Bill of Materials (BOM) --> <dependencyManagement> <dependencies> <dependency> <groupId>com.google.api-ads</groupId> <artifactId>google-ads-bom</artifactId> <version>40.0.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- Add the google-ads dependency without a version --> <dependencies> <dependency> <groupId>com.google.api-ads</groupId> <artifactId>google-ads</artifactId> </dependency> </dependencies>
如何在 Gradle 專案中加入 BOM:
// Import the Bill of Materials (BOM). implementation platform('com.google.api-ads:google-ads-bom:40.0.0') // Add the google-ads dependency, without a version. The version is managed by the BOM. implementation 'com.google.api-ads:google-ads'
宣告 google-ads-bom 涵蓋的依附元件
BOM 會自動管理多個常見程式庫的版本,例如 Guava、Protobuf、GAX 和 gRPC,確保這些程式庫相容。為避免潛在的依附元件衝突,請勿在宣告這些依附元件時指定版本。舉例來說,如果您使用的是 Guava,則宣告時不需指定版本:
在 Maven 中:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>或在 Gradle 中:
implementation 'com.google.guava:guava' // NO VERSION SPECIFIED.
如要擷取可使用 BOM 匯入且未宣告版本的受限依附元件清單,請使用 listAllDependencyConstraints gradle 工作。
如要進一步瞭解這項新的 google-ads-bom 服務,以及如何設定 Java 用戶端,請參閱入門指南。
標籤: google-ads-api