编译 sbt 时找不到隐式值

could not find implicit value when i compile the sbt

我有一个配置为 Dependencias.scalabuild.sbt、[=22= 的 sbt 项目]plugins.sbt,我有这个依赖:https://christopherdavenport.github.io/cormorant/

 lazy val `cormorant-core`         = "io.chrisdavenport"       %% "cormorant-core"           % Version.cormorant
  lazy val `cormorant-generic`      = "io.chrisdavenport"       %% "cormorant-generic"        % Version.cormorant
  lazy val `cormorant-parser`       = "io.chrisdavenport"       %% "cormorant-parser"         % Version.cormorant
  lazy val `cormorant-http4s`       = "io.chrisdavenport"       %% "cormorant-http4s"         % Version.cormorant
  lazy val `cormorant-refined`      = "io.chrisdavenport"       %% "cormorant-refined"        % Version.cormorant

当我编译它时:sbt compile,出现这个错误:

[error] /home/javier/IdeaProjects/ERPFetcherJavs/src/main/scala/com/arkondata/bipo/utils/CSVHandler.scala:11:53: could not find implicit value for parameter gen: shapeless.LabelledGeneric.Aux[A,H]
[error]   private implicit val lr: LabelledRead[ItemData] = deriveLabelledRead
[error]                                                     ^
[error] /home/javier/IdeaProjects/ERPFetcherJavs/src/main/scala/com/arkondata/bipo/utils/CSVHandler.scala:13:54: could not find implicit value for parameter gen: shapeless.LabelledGeneric.Aux[A,H]
[error]   private implicit val lw: LabelledWrite[ItemData] = deriveLabelledWrite
[error]                                                      ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed

我该如何解决?

我们假设 ItemData 是一个简单的案例 class,例如:

case class ItemData(a: String)

然后,当运行上面的代码时,上面的错误重现。为什么会这样?

deriveLabelledReadpackage io.chrisdavenport.cormorant.generic 处的一种方法,它需要 2 个隐式:

def deriveLabelledRead[A, H <: HList](
  implicit gen: LabelledGeneric.Aux[A, H],
  hlw: Lazy[LabelledRead[H]])

阅读 docs 后,我们需要进行大量导入:

import io.chrisdavenport.cormorant._
import io.chrisdavenport.cormorant.generic.semiauto._
import io.chrisdavenport.cormorant.parser._
import io.chrisdavenport.cormorant.implicits._
import cats.implicits._
import java.util.UUID
import java.time.Instant

导入这些内容时,deriveLabelledRead 具有正确创建所需的隐式内容。