はじめに
以下の書籍をやっていたところエラーに遭遇して解決に時間がかかったのでまとめます
出版が数年前だったためそれが原因でエラーが発生していました
問題
KtorのプラグインにLocations
を追加しました
しかし以下のエラーが発生しました
com.example.thanks-bank-test:test: Could not find io.ktor:ktor-locations:2.2.1.
バージョン不一致が起きているようです
解決方法
以下のログからアクセスしたところ
> Could not find io.ktor:ktor-locations:2.2.1.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/io/ktor/ktor-locations/2.2.1/ktor-locations-2.2.1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :
バージョンが1.6.6
までしかありません
ktorはバージョン2.2.1
を利用しているためどうすればよいかわからなくなりました
公式を見たところ以下の記述を発見
In v2.0.0, the Locations plugin is deprecated. Use the Resources plugin instead.
2.0.0
からは廃止されて代わりにresources
を利用するようになったそうです
プロジェクトを作成し直してlocations
のかわりにresources
を入れました
また、デフォルトのRoutesだとインポートが足りておらずArticle
にエラーが表示される
ので以下を追加しました
import io.ktor.server.routing.get
するとサーバーが立ち上がりました
おわりに
この書籍はかなり詳しくKotlinならではの機能の説明をしていたり、実践的なアプリを作成したりするのでやりきれたら力になりそうだなと思っています
バージョンが古いので読み替える必要はありそうですが、できる限りがんばりたいです
参考
https://engineering.visional.inc/blog/_324/ktor-routing/
https://ktor.io/docs/locations.html