sbt, intellij jar in external library but not found when compile - scala

encounter a very strange problem.
I'm trying to use reactivemongo. And after update build.sbt
I can see that the jar is in the external library. However the compilation failed because not found object reactivemongo.
my build.sbt is:
hereenter code herelazy val commonSettings = Seq(
hereorganization := "emmettng.com",
hereversion := "0.0.1",
scalaVersion := "2.11.8"
)
hereresolvers += "Typesafe Repo" at"http://repo.typesafe.com/typesafe/releases/"
resolvers += "Typesafe repository releases" at"http://repo.typesafe.com/typesafe/releases/"`
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % "2.11.8",
"org.scala-lang.modules" % "scala-xml_2.11" % "1.0.4",
``"org.scalatest" %% "scalatest" % "3.0.0" % "test",
"com.typesafe.play" %% "play-json" % "2.4.0-M3",
"org.scalaz" %% "scalaz-core" % "7.2.5",
"junit" % "junit" % "4.10" % "test",
"org.reactivemongo" %% "reactivemongo" % "0.11.14"
)

Related

sbt complains about JmhPlugin not found

I'm trying to use sbt JmhPlugin and I'm following the instructions found here: https://github.com/sbt/sbt-jmh
So I added the plugin to project/plugins.sbt and then I added to build.sbt the enablePlugins(JmhPlugin) line so my build files look like this:
project/plugins.sbt:
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4")
project/build.properties:
sbt.version = 1.8.2
build.sbt:
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.10"
lazy val root = (project in file("."))
.settings(
name := "myproj"
)
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.15"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.15" % "test"
libraryDependencies += "org.typelevel" %% "cats-effect" % "2.5.3"
val catsVersion = "2.9.0"
libraryDependencies += "org.typelevel" %% "cats-core" % catsVersion
libraryDependencies += "org.typelevel" %% "cats-free" % catsVersion
libraryDependencies += "org.typelevel" %% "cats-laws" % catsVersion
libraryDependencies += "org.typelevel" %% "cats-mtl-core" % "0.7.1"
libraryDependencies += "org.typelevel" %% "simulacrum" % "1.0.1"
libraryDependencies += "org.scalamacros" %% "resetallattrs" % "1.0.0"
libraryDependencies += "org.scalameta" %% "munit" % "0.7.22"
libraryDependencies += "org.typelevel" %% "discipline-munit" % "1.0.6"
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:_",
"-Ymacro-annotations"
)
enablePlugins(JmhPlugin)
but when I'm running sbt build it complains that it cannot find the JmhPlugin:
error: not found: value JmhPlugin
enablePlugins(JmhPlugin)
^
What am I doing wrong here? Also, how should I debug this issue?
Thanks!

how to resolve NoSuchMethodError on typesafe config?

I'm getting this error when trying to run my project.
Exception in thread "main" java.lang.NoSuchMethodError:
com.typesafe.config.Config.getDuration(Ljava/lang/String;)Ljava/time/Duration;
tried to clear ivy2 cache with no success .
this is how my build sbt looks like :
scalaVersion := "2.11.7"
scalacOptions := Seq("-unchecked", "-feature", "-deprecation", "-encoding", "utf8")
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots"),
Resolver.bintrayRepo("websudos", "oss-releases"),
"spray repo" at "http://repo.spray.io",
"Typesafe repository snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
"Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/",
"Sonatype repo" at "https://oss.sonatype.org/content/groups/scala-tools/",
"Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases",
"Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype staging" at "http://oss.sonatype.org/content/repositories/staging",
"Sonatype" at "https://oss.sonatype.org/content/groups/public/",
"Java.net Maven2 Repository" at "http://download.java.net/maven/2/",
"Twitter Repository" at "http://maven.twttr.com"
)
libraryDependencies ++= {
val phantomV = "1.29.5"
val scalaTestV = "3.0.0"
val elastic4sV = "2.4.0"
val akkaStreamVersion = "2.4.2"
val akkaVersion = "2.3.11"
Seq(
"com.websudos" %% "phantom-dsl" % phantomV,
"com.websudos" %% "phantom-reactivestreams" % phantomV,
"com.websudos" %% "util-testing" % "0.13.0" % "test, provided",
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-http-spray-json-experimental" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-http-core" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-http-experimental" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-http-testkit" % akkaStreamVersion,
"org.scalatest" %% "scalatest" % scalaTestV % "test",
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"com.typesafe.play" %% "play-streams-experimental" % "2.4.6",
"com.sksamuel.elastic4s" %% "elastic4s-core" % elastic4sV,
"com.sksamuel.elastic4s" %% "elastic4s-streams" % elastic4sV
)
}
lazy val root = project.in(file(".")).configs(IntegrationTest)
Defaults.itSettings
initialCommands := """|import akka.actor._
|import akka.pattern._
|import akka.util._
|import scala.concurrent._
|import scala.concurrent.duration._""".stripMargin
fork in run := true
any idea how to solve it ?
UPDATE:
java.class.path shows
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/lib/tools.jar:/Applications/IntelliJ
IDEA.app/Contents/lib/jps-builders.jar:/Applications/IntelliJ
IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ
IDEA.app/Contents/lib/trove4j.jar:/Users/avi/Library/Application
Support/IntelliJIdea2016.2/Scala/lib/scala-library.jar:/Users/avi/Library/Application
Support/IntelliJIdea2016.2/Scala/lib/scala-nailgun-runner.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/compiler-settings.jar:/Users/avi/Library/Application
Support/IntelliJIdea2016.2/Scala/lib/jps/nailgun.jar:/Users/avi/Library/Application
Support/IntelliJIdea2016.2/Scala/lib/jps/sbt-interface.jar:/Users/avi/Library/Application
Support/IntelliJIdea2016.2/Scala/lib/jps/incremental-compiler.jar:/Users/avi/Library/Application
Support/IntelliJIdea2016.2/Scala/lib/jps/scala-jps-plugin.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/dotty-interfaces.jar
Adding TypeSafe 1.3.1 as dependency might help, add it as part of your Seq() of dependencies:
"com.typesafe" % "config" % "1.3.1"
It sounds like a classpath problem. You may be using a library that calls (uses) Typesafe Config, but the version of Typesafe Config in your path is less than 1.3.0. The method that is not found was introduced in Typesafe Config 1.3.0. To see your runtime classpath, make sure these statements are the first ones that are executed (i.e. before your app crashes):
val cp = System.getProperty("java.class.path")
val sep = System.getProperty("path.separator")
cp.split(sep).foreach(println)
Once you see that you do not have Typesafe Config 1.3.0, add it as an explicit dependency.

missing or invalid dependency detected while loading class file 'JodaSetParameter.class'

I'm using this build.sbt
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
routesGenerator := InjectedRoutesGenerator
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-slick" % "2.0.0",
"com.typesafe.play" %% "play-slick-evolutions" % "2.0.0",
"com.h2database" % "h2" % "1.4.187",
"mysql" % "mysql-connector-java" % "5.1.34",
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.0" % "test",
specs2 % Test
)
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "2.1.0",
"com.github.tototoshi" %% "slick-joda-mapper" % "1.2.0",
"joda-time" % "joda-time" % "2.7",
"org.joda" % "joda-convert" % "1.7"
)
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
fork in run := true
and the following errors happens:
missing or invalid dependency detected while loading class file
'JodaSetParameter.class'.
What am I missing? Should I be using a different version of joda?

Spray microservice assembly deduplicate

I'm using this template to develop a microservice:
http://www.typesafe.com/activator/template/activator-service-container-tutorial
My sbt file is like this:
import sbt._
import Keys._
name := "activator-service-container-tutorial"
version := "1.0.1"
scalaVersion := "2.11.6"
crossScalaVersions := Seq("2.10.5", "2.11.6")
resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
libraryDependencies ++= {
val containerVersion = "1.0.1"
val configVersion = "1.2.1"
val akkaVersion = "2.3.9"
val liftVersion = "2.6.2"
val sprayVersion = "1.3.3"
Seq(
"com.github.vonnagy" %% "service-container" % containerVersion,
"com.github.vonnagy" %% "service-container-metrics-reporting" % containerVersion,
"com.typesafe" % "config" % configVersion,
"com.typesafe.akka" %% "akka-actor" % akkaVersion exclude ("org.scala-lang" , "scala-library"),
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion exclude ("org.slf4j", "slf4j-api") exclude ("org.scala-lang" , "scala-library"),
"ch.qos.logback" % "logback-classic" % "1.1.3",
"io.spray" %% "spray-can" % sprayVersion,
"io.spray" %% "spray-routing" % sprayVersion,
"net.liftweb" %% "lift-json" % liftVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"io.spray" %% "spray-testkit" % sprayVersion % "test",
"junit" % "junit" % "4.12" % "test",
"org.scalaz.stream" %% "scalaz-stream" % "0.7a" % "test",
"org.specs2" %% "specs2-core" % "3.5" % "test",
"org.specs2" %% "specs2-mock" % "3.5" % "test",
"com.twitter" %% "finagle-http" % "6.25.0",
"com.twitter" %% "bijection-util" % "0.7.2"
)
}
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-Xlint",
"-Ywarn-dead-code",
"-language:_",
"-target:jvm-1.7",
"-encoding", "UTF-8"
)
crossPaths := false
parallelExecution in Test := false
assemblyJarName in assembly := "santo.jar"
mainClass in assembly := Some("Service")
The project compiles fine!
But when I run assembly, the terminal show me this:
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /path/.ivy2/cache/io.dropwizard.metrics/metrics-core/bundles/metrics-core-3.1.1.jar:com/codahale/metrics/ConsoleReporter$1.class
[error] /path/.ivy2/cache/com.codahale.metrics/metrics-core/bundles/metrics-core-3.0.1.jar:com/codahale/metrics/ConsoleReporter$1.class
What options do I have to fix it?
Thanks
The issue as it seems transitive dependency of the dependency is resulting with two different versions of metrics-core. The best thing to do would be to used the right library dependency so that you end up with a single version of this library. Please use https://github.com/jrudolph/sbt-dependency-graph , if it is difficult to figure out dependencies.
If it is not possible to get to a single version then you would most likely to go down exclude route . I assume, this only work, if there is compatibility between the all required versions.

Value webSettings not found error in a Scalatra project

I have a Scalatra project with the following build.sbt
organization := "com.example"
name := "scalatra-project"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.9.1"
seq(webSettings :_*)
libraryDependencies ++= Seq(
"org.scalatra" %% "scalatra" % "2.0.1",
"org.scalatra" %% "scalatra-scalate" % "2.0.1",
"org.scalatra" %% "scalatra-specs" % "2.0.2",
"org.scala-tools.testing" %% "specs" % "1.6.9",
"org.eclipse.jetty" % "jetty-webapp" % "7.4.5.v20110725" % "container",
"javax.servlet" % "servlet-api" % "2.5" % "provided",
"net.liftweb" %% "lift-json" % "2.4-SNAPSHOT",
"net.liftweb" %% "lift-mongodb" % "2.4-M5",
"net.liftweb" %% "lift-mongodb-record" % "2.4-M5"
)
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/"
resolvers += "Scala Tools Releases" at "http://scala-tools.org/repo-releases/"
resolvers += "Maven Repo" at "http://repo1.maven.org/maven2"
When I run sbt, I get the following error:
error: not found: value webSettings seq(webSettings :_*)
How can I fix this problem?
check the plugin settings as mentioned here https://github.com/siasia/xsbt-web-plugin