この競合は、Tablestore SDK for Java にバンドルされている protobuf-java または httpasyncclient のバージョンが、ご利用の Maven プロジェクト内の他の依存関係によって取り込まれたバージョンと衝突する場合に発生します。jar-with-dependencies 分類器を使用して解決してください。
競合を診断するには、ご利用のリポジトリで mvn dependency:tree コマンドを実行し、出力結果に protobuf-java、httpasyncclient、または tablestore の複数のバージョンが存在しないか確認します。
問題の説明
Tablestore SDK for Java を使用する際に、次の例外が発生します。
Caused by: java.lang.UnsupportedOperationException: This is supposed to be overridden by subclassed
at com.google.protobuf.GeneratedMessage.getUnknownFields(GeneratedMessage.java:225)
原因
Tablestore SDK for Java は protobuf-java V2.4.1 および httpasyncclient V4.0.2 に依存しています。プロジェクト自体、またはプロジェクトが依存するライブラリがこれらのアーティファクトの異なるバージョンを取り込む場合、Maven はランタイム時に競合するクラス定義をロードし、上記の例外をトリガーします。
ソリューション
tablestore アーティファクトの jar-with-dependencies 分類器を使用してください。このバリアントはパッケージリロケーションにより、protobuf-java および httpasyncclient をリネームされたパッケージ名前空間の下にバンドルするため、クラスパス上のこれらのライブラリの他のバージョンとの競合が解消されます。
pom.xml に以下の内容を追加します。
jar-with-dependencies 分類器はパッケージリロケーションにより protobuf-java および httpasyncclient をバンドルし、両ライブラリに対する外部依存関係を削除します。
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore</artifactId>
<version>Your current version</version>
<classifier>jar-with-dependencies</classifier>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- 例:以下のライブラリは間接的に Tablestore SDK に依存しています -->
<groupId>com.aliyun.xxxxxxx</groupId>
<artifactId>yyyyyy</artifactId>
<version>zzzzzzz</version>
<classifier>jar-with-dependencies</classifier>
<exclusions>
<!-- tablestore ライブラリに対する間接的な依存関係を除外します -->
<exclusion>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore</artifactId>
</exclusion>
</exclusions>
</dependency>