0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ktorにLocationsをいれようとするとバージョンエラーがでる

Last updated at Posted at 2023-01-03

はじめに

以下の書籍をやっていたところエラーに遭遇して解決に時間がかかったのでまとめます

出版が数年前だったためそれが原因でエラーが発生していました

問題

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 :

image.png

バージョンが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を入れました

image.png

また、デフォルトのRoutesだとインポートが足りておらずArticleにエラーが表示される
ので以下を追加しました

import io.ktor.server.routing.get

するとサーバーが立ち上がりました

おわりに

この書籍はかなり詳しくKotlinならではの機能の説明をしていたり、実践的なアプリを作成したりするのでやりきれたら力になりそうだなと思っています
バージョンが古いので読み替える必要はありそうですが、できる限りがんばりたいです

参考

https://engineering.visional.inc/blog/_324/ktor-routing/
https://ktor.io/docs/locations.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?