softshipper
softshipper

Reputation: 34119

Can not resolve symbol Arbitrary

I am trying to implement Arbitrary for my type as follow:

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)))


}

and the compiler complains:

 object scalacheck is not a member of package org
[error] import org.scalacheck.{Arbitrary, Gen}

I using intellj and the import is marked as red:

enter image description here

I also checked the build.sbt file:

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)

and I should be correct. What is missing?

Update The implementation is in Server.scala marked on the image:

enter image description here

the serversupervisor project it depends on the core project, because there are some common libs.

Upvotes: 2

Views: 177

Answers (1)

laughedelic
laughedelic

Reputation: 6460

You use this in the Compile scope (i.e. sources in src/main), so you need to remove % "test" from the ScalaCheck dependency. Or move that source to the Test scope (i.e. in src/test)

Upvotes: 3

Related Questions