playframework 2.2.0 scala mockito test - scala

I am currently trying to use Mockclasses in play framework for testing.
I have implemented everything like written in the Documentation. Unfortunately the compiler says:
[error] bad symbolic reference. A signature in MockitoStubs.class refers to term stubbing
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MockitoStubs.class.
I found some other people which are running play on a mac and have the same error but i could not find any solution.
Does anyone have a solution for this problem? Is it a problem with the mac jdk maybe?

I just installed the new OS X 10.9 Version which included a xCode Update and SDK Updates(I guess Java got updated too). Anyways the error does not occur anymore so it probably was a problem with the jdk...

Mockito is an optional dependency (like most Play2 dependencies). Excerpt from my Build.scala:
"org.mockito" % "mockito-all" % "1.9.5"

Related

Can scalameter be imported to scala3 projects (and how)?

I tried to use scalameter 0.21 (and some other versions) with scala 3.1.2.
I added some configurations from the scalameter web-page in my build.sbt file and tried serveral things to make this work, but sbt was not able to find the desired packages.
I would have concluded that scalameter is simply not available for scala3, but there is a question here where somebody somehow got it to work.
The problem seemed to bee that sbt added a 3 in all the sources, as in:
https://repo1.maven.org/maven2/com/storm-enroute/scalameter_3/0.21/scalameter_3-0.21.pom
but the path with scalameter_3 did not exist. If I change the scalaversion to 2.13.8, sbt is able to download all the nesessary files without error. Starting with scala version 3.0.0 the problem exists.
If somebody could post a build.sbt file where scalameter and scala3 are used together, I would apreciate it.
Otherwise, if somebody knows a different library for benchmarking with scala 3...
Thanks very much
As #maxkar mentioned, using crossVersion should do the job:
("com.storm-enroute" %% "scalameter" % "0.21").cross(CrossVersion.for3Use2_13) % Test
However, doing so, you may encounter a problem with conflicting dependencies, e.g.:
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(...
[error] org.scala-lang.modules:scala-xml _2.13, _3
In such a case, dependency exclusion, as described in sbt documentation, should solve the issue:
("com.storm-enroute" %% "scalameter" % "0.21").cross(CrossVersion.for3Use2_13) % Test exclude("org.scala-lang.modules", "scala-xml_2.13")
I'm not sure if this cannot backfire in certain situations, but it worked perfectly in my case.

jOOQ as a dependency in Scala 3 is broken?

I am trying to use jOOQ as dependency in a Scala 3 codebase:
libraryDependencies ++= Seq("org.jooq" % "jooq" % "3.16.6")
However when I try to do an import from this library -- like import org.jooq.DSLContext -- I get a compilation error.
The easiest way to reproduce this is using ammonite:
cs launch ammonite --scala 3.1.3
Loading...
Welcome to the Ammonite Repl 2.5.4-11-4f5bf2aa (Scala 3.1.3 Java 11.0.15)
# import $ivy.`org.jooq:jooq:3.16.6`, org.jooq.DSLContext
Bad symbolic reference. A signature
refers to ApiStatus/T in package org.jetbrains.annotations which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling the signature.
Caught: java.lang.AssertionError: assertion failed: failure to resolve inner class:
externalName = org.jetbrains.annotations.ApiStatus$Experimental,
outerName = org.jetbrains.annotations.ApiStatus,
innerName = Experimental
owner.fullName = org.jetbrains.annotations.ApiStatus
while parsing /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class) while parsing annotations in /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class)
Caught: java.lang.RuntimeException: bad constant pool index: 0 at pos: 740 while parsing annotations in /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class)
...
This is not the complete error, it gives the same type of error on a bunch of different classes, always related with this annotation org.jetbrains.annotations.ApiStatus.Experimental.
I've reproduced this using Java 11 and 18 (openjdk), using SBT and ammonite, with all versions of Scala 3.
When using Scala 2.13.* everything works correctly, we're using that in production.
Any idea what might be going on here? Any potential clues or possible workarounds?
This is fixed in Scala 3 from version 3.2.0-RC1.
See reddit post in r/scala.

"Referring to non-existent method org.scalatest.Matchers.convertToAnyShouldWrapper" after upgrading scalatest to 3.1.4

I've scala and scalajs project and it is in github for reference.
Initially I've scalatest version 3.0.3 and scalacheck version 1.13.5. The command sbt clean test is working fine.
I've updated scalatest version to 3.1.4 and scalacheck version 1.14.3.
After this updated scala project tests are working fine but scalajs tests are not.
The error I'm getting is
[info] Fast optimizing /Users/rajkumar.natarajan/Documents/Coding/misc/sjs-test-error/core/js/target/scala-2.12/reftree-test-fastopt.js
[error] Referring to non-existent method org.scalatestplus.scalacheck.ScalaCheckConfiguration.$$init$()scala.Unit
[error] called from generic.RefTreeSpec.()
[error] called from generic.RefTreeSpec.()
[error] called from core module analyzer
[error] Referring to non-existent method org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks.$$init$()scala.Unit
[error] called from generic.RefTreeSpec.()
[error] called from generic.RefTreeSpec.()
[error] called from core module analyzer
[error] There were linking errors
[error] (coreJS / Test / fastOptJS) There were linking errors
[error] Total time: 31 s, completed Jun 9, 2021, 5:54:57 PM
The changes are in this commit.
I tried to figure out but I'm novice in scalajs. Is there anything extra I need to do to work correctly?
In your diff, at https://github.com/rajcspsg/sjs-test-error/commit/bb3f00cc542b29998af271530dccae9b73f2ad00#diff-5634c415cd8c8504fdb973a3ed092300b43c4b8fc1e184f7249eb29a55511f91R33, you have a dependency on
"org.scalatestplus" %% "scalacheck-1-14" % "3.1.3.0" % Test
which uses %%. This is a dependency on a JVM artifact, which brings the JVM version of its own dependencies. You end up with two versions of ScalaTest on your classpath: one for the JVM and one for JS. With bad luck, the one for the JVM gets selected, and therefore shadows the one for JS. This results in the linking errors that you get.
You can fix this by using %%% instead of %% in that dependency, assuming that that library is available for Scala.js. If it isn't, you'll have to find a way not to need that dependency at all.

Conflicting cross-version suffixes in: org.scalamacros:quasiquotes

I am trying to use scala-pickling in one of my projects. I tried to mimic the build file of macroid which seems to use pickling too but I keep getting this error on sbt test:
[error] Modules were resolved with conflicting cross-version suffixes in dijon:
[error] org.scalamacros:quasiquotes _2.10, _2.10.3
java.lang.RuntimeException: Conflicting cross-version suffixes in: org.scalamacros:quasiquotes
at scala.sys.package$.error(package.scala:27)
at sbt.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:47)
at sbt.ConflictWarning$.apply(ConflictWarning.scala:30)
at sbt.Classpaths$$anonfun$61.apply(Defaults.scala:1044)
at sbt.Classpaths$$anonfun$61.apply(Defaults.scala:1044)
Full build log is here. What am I doing wrong? What should I change in my build.sbt to fix this? I also should be able to cross compile and release my library against both 2.10.x and 2.11.x.
Starting from 2.0.0-M7, org.scalamacros % quasiquotes are cross-versioned as binary (i.e. _2.10) and not as full (i.e. _2.10.x): http://scalamacros.org/news/2014/04/03/macro-paradise-2.0.0-M7.html. Looks like one of your dependencies uses pre-M7 quasiquotes and another one uses post-M7 quasiquotes.
I don't think this can fixed in any way other than upgrading all the dependencies that use the old quasiquote library, because pre-M7 and post-M7 quasiquote libraries are incompatible.
The problem is that you are using two different versions of the quasiquotes module that allows defining Scala macros. You should make sure that only a single version is used, and that this single version is matched by all your dependencies that use macros.
Also, are you sure that scala-pickling was released for Scala 2.11.x? Judging, from their build file, they released only for 2.10.3 - https://github.com/scala/pickling/blob/2.10.x/project/Build.scala#L10.
First, try to remove:
crossScalaVersions := Seq("2.10.4", "2.11.0-RC4")
And try again. After that, set the Scala version to 2.10.3, so that it matches the one in scala-pickling.
scalaVersion := "2.10.3"
EDIT: See Eugene's answer below for a more detailed explanation.
According to my dependencyGraph from pulling in spray-testkit_2.10-1.3.2, specs2_2.10 v1.3.10 is still using a milestone release of quasiquotes. I ran the cross version error issue because of this.

strange error message: bad symbolic reference. A signature in package.class refers to term apache in package org which is not available

When I tried to compile simple typesafe' akka program (scala 2.10, akka, 2.1.0):
scalac -cp "akka-actor_2.10-2.1.0.jar:akka-camel_2.10-2.1.0.jar" write2.scala
error: bad symbolic reference. A signature in package.class refers to term apache
in package org which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.
error: bad symbolic reference. A signature in package.class refers to term camel
in value org.apache which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.
write2.scala:21: error: bad symbolic reference. A signature in package.class refers to term model
in value org.camel which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.
val mina = system.actorOf(Props[MyEndPoint])
three errors found
The code on line 21:
val mina = system.actorOf(Props[MyEndPoint])
(The same program was compiled correctly in Eclipse, so the source code is OK)
Most likely some jar file is missing in -cp variable. The question is what mean that strange/useless error message.
Thanks, Tomas
The message says "There's no package org.apache in my classpath, and I need it while reading file package.class". Pass -Ylog-classpath to scalac and look at what is the real classpath that gets to the compiler.
To me it was JDK not set on PATH neither JAVA_HOME
You can add JAVA_HOME to point to your JDK root folder and add jdk/bin folder (wich inludes javac) directly to the path.
You can refer to the Oracle docs for instruccions on how to add the path
http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html
In case this helps anyone in the future, I was having this problem with an application I adopted after adding a new class. It turned out that the capitalization in the package name in each class within the package and the actual directory structure were different. Once I lower-cased all of the directory it started working again.
First time Scala user. I had some problems in configuring my eclipse and I used to get:
Error:scalac: bad symbolic reference. A signature in package.class refers to type compileTimeOnly
in package scala.annotation which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.
Finally found that scala test version 2.11 and compiler version should match.
Downloaded scala version 2.11-RC1