状況
Mavenを使用した開発をVSCodeで行っていた。VSCodeの拡張機能 Maven for Java を使って"Guava"を依存先として追加したところ、pom.xml
に以下のように追記された。
pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<type>bundle</type>
</dependency>
すると以下のようなエラーが発生した。
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.093 s
[INFO] Finished at: 2023-04-01T00:31:50+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project [プロジェクト名]: The following artifacts could not be resolved: com.google.guava:guava:bundle:31.1-jre (absent): com.google.guava:guava:bundle:31.1-jre was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
解決策
<type>
タグを取る。
pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
- <type>bundle</type>
</dependency>
これだけで動くようになった。
<type>bundle</type>
という記述が何を意味しているのか調べてみたが、ネット上にはこれくらいの記述しかなかった。この記事によると、この記述があると.jar
ファイルにまとめてバンドルできるとか何とか。でもドキュメントを見てもbundle
というタイプはなさそう。何だったのだろうか。
拡張機能を盲信してはならぬ。