首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能任意解析符号

不能任意解析符号
EN

Stack Overflow用户
提问于 2019-09-17 19:33:31
回答 1查看 139关注 0票数 2

我试图为我的类型实现Arbitrary,如下所示:

代码语言:javascript
复制
import cats._
import org.scalacheck.{Arbitrary, Gen}


object Server {

  sealed trait ServerHealth

  case object ServerOnline extends ServerHealth

  case object ServerOffline extends ServerHealth


  implicit val healthSemigroup: Semigroup[ServerHealth] = (x: ServerHealth, y: ServerHealth) => x match {
    case ServerOnline if y == ServerOnline => ServerOnline
    case ServerOffline => ServerOffline
  }

  implicit val healthEq: Eq[ServerHealth] = (x: ServerHealth, y: ServerHealth) => x match {
    case ServerOnline if y == ServerOnline => true
    case ServerOffline => false
  }

  implicit def healthArbitrary[A: Arbitrary]: Arbitrary[ServerHealth] =
    Arbitrary(Gen.oneOf(Gen.const(ServerOffline), for {
      e <- Arbitrary.arbitrary[A]
    } yield (ServerOffline, ServerOnline)))


}

编译器抱怨:

代码语言:javascript
复制
 object scalacheck is not a member of package org
[error] import org.scalacheck.{Arbitrary, Gen}

I使用intellj,导入标记为红色:

我还检查了build.sbt文件:

代码语言:javascript
复制
val Http4sVersion = "0.21.0-M4"
val CirceVersion = "0.12.1"
val Specs2Version = "4.7.0"
val LogbackVersion = "1.2.3"
val ScalaTestVersion = "3.0.8"
val TestContainerVersion = "1.11.3"
val KafkaTestContainerVersion = "1.11.3"
val ConfigVersion = "1.3.4"
val SpringVersion = "5.1.8.RELEASE"
val catsVersion = "2.0.0"


lazy val settings = Seq(
  organization := "com.sweetsoft",
  name := "connector",
  scalaVersion := "2.13.0",
  addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
  addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0"),
  scalacOptions ++= Seq(
    "-deprecation",
    "-encoding", "UTF-8",
    "-language:higherKinds",
    "-language:postfixOps",
    "-feature",
    "-Xfatal-warnings",
  ),
  scalacOptions in(Compile, console) ~= {
    _.filterNot(Set("-Xlint"))
  }

)

lazy val dependencies = Seq(
  "org.http4s" %% "http4s-blaze-server" % Http4sVersion,
  "org.http4s" %% "http4s-blaze-client" % Http4sVersion,
  "org.http4s" %% "http4s-circe" % Http4sVersion,
  "org.http4s" %% "http4s-dsl" % Http4sVersion,
  "io.circe" %% "circe-generic" % CirceVersion,
  "ch.qos.logback" % "logback-classic" % LogbackVersion,
  "org.typelevel" %% "cats-core" % catsVersion,
  "com.typesafe" % "config" % ConfigVersion % "test",
  "org.scalactic" %% "scalactic" % ScalaTestVersion % "test",
  "org.scalatest" %% "scalatest" % ScalaTestVersion % "test",
  "org.testcontainers" % "testcontainers" % TestContainerVersion % "test",
  "org.testcontainers" % "kafka" % KafkaTestContainerVersion % "test",
  "org.springframework" % "spring-core" % SpringVersion % "test",
  "org.typelevel" %% "cats-laws" % catsVersion % "test",
  "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.3" % "test",
  "org.scalacheck" %% "scalacheck" % "1.14.0" % "test"
)



lazy val global = project
  .in(file("."))
  .settings(settings)
  .aggregate(core, serversupervisor)


lazy val core = (project in file("core"))
  .settings(
    settings,
    libraryDependencies ++= dependencies
  )


lazy val serversupervisor = (project in file("serversupervisor"))
  .settings(
    settings,
    libraryDependencies ++= dependencies
  )
  .dependsOn(core)

我应该是对的。少了什么?

更新实现在图像上标记为Server.scala

serversupervisor项目--它依赖于core项目,因为有一些常见的库。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-17 22:48:11

您可以在Compile作用域(即src/main中的源代码)中使用这一点,因此需要从ScalaCheck依赖项中删除% "test"。或将该源移动到Test范围(即在src/test中)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57980932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档