Class Resolving in one namespace, but not the other - scala

When running play compile, I get a compile-time error.
[error] test.scala:14: object BOMInputStream is not a member of package org.ap
ache.commons.io.input
[error] import org.apache.commons.io.input.BOMInputStream
[error] ^
[error] test.scala:80: not found: type BOMInputStream
[error] val bomIn = new BOMInputStream(fileInpStream, false)
[error] ^
[error] two errors found
However, I successfully ran a scalatest test using the BOMInputStream in the same play project within the /test directory.
When I comment out the offending lines in the above compile-time error, the test succeeds.
Note that I've updated my /project/Build.scala appropriately:
"org.apache.commons" % "commons-io" % "1.3.2"

After deleting a JAR, which contained the BOMInputStream class, from my PLAY-PROJECT/lib/ directory, I was able to compile.

Related

Iteratee is not a member of package play.api.libs

While upgrading from play 2.4 -> 2.5 I hit an issue where
Symbol 'type <none>.iteratee.Iteratee' is missing from the classpath
I checked the migration guide and included the dependency "com.typesafe.play" % "play-iteratees_2.11" % 2.5.18 into sbt. From the new play-iteratees repo, I was under the impression that package play.api.libs.iteratee is where I'd find what to import. But it doesnt seem to work?
Error log:
[error] /Users/arnogau/Documents/alice/common/src/main/scala/common/util/Autodesk.scala:23: object iteratee is not a member of package play.api.libs
[error] import play.api.libs.iteratee.Iteratee
[error] ^
[error] /Users/arnogau/Documents/alice/common/src/main/scala/common/util/Autodesk.scala:158: Symbol 'type <none>.iteratee.Iteratee' is missing from the classpath.
[error] This symbol is required by 'method play.api.libs.ws.WSRequest.get'.
[error] Make sure that type Iteratee is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'WSRequest.class' was compiled against an incompatible version of <none>.iteratee.
[error] val req = client.url(MANIFEST_URL(urn)).withToken(token).get()
[error] ^
[error] two errors found

ScalaJS and MongoDB driver: Referring to non-existent class

Learning Scala since yesterday, I've build a project to interact with a MongoDB index (which works fine) and another one using ScalaJS to do the same thing.
Here is my build.sbt :
enablePlugins(ScalaJSPlugin)
name := "demographics"
version := "1.0"
scalaVersion := "2.12.1"
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "1.2.1"
libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.9.1"
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.1"
skip in packageJSDependencies := false
jsDependencies +=
"org.webjars" % "jquery" % "3.1.1" / "3.1.1/jquery.js"
and my main file:
package demographics.webapp
import org.mongodb.scala._
import scala.scalajs.js.JSApp
object DemographicsApp extends JSApp {
def main(): Unit = {
// connect to the bdd
val mongoClient: MongoClient = MongoClient()
val database: MongoDatabase = mongoClient.getDatabase("demographics")
val collection: MongoCollection[Document] = database.getCollection("demographics")
}
}
Very basic: just connect to the collection.
Sadly, when I launch a "fastOptJS" on the sbt shell, the following error appears:
[info] Compiling 1 Scala source to C:\...\target\scala-2.12\classes...
[info] Fast optimizing C:\...\target\scala-2.12\untitled1-fastopt.js
[error] Referring to non-existent class org.mongodb.scala.bson.DefaultHelper$DefaultsTo$
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.DemographicsApp$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] demographics.webapp.PrenomApp$
[error] Referring to non-existent class org.mongodb.scala.MongoClient$
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.DemographicsApp$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] demographics.webapp.DemographicsApp$
[error] Referring to non-existent class org.mongodb.scala.bson.collection.immutable.Document
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.DemographicsApp$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] demographics.webapp.DemographicsApp$
[error] Referring to non-existent method org.mongodb.scala.bson.DefaultHelper$DefaultsTo$.$default()org.mongodb.scala.bson.DefaultHelper$DefaultsTo
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.DemographicsApp$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] demographics.webapp.DemographicsApp$
[error] Referring to non-existent method org.mongodb.scala.MongoClient$.apply()org.mongodb.scala.MongoClient
[error] called from demographics.webapp.DemographicsApp$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.PrenomApp$.$$js$exported$meth$main()java.lang.Object
[error] called from demographics.webapp.DemographicsApp$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] demographics.webapp.DemographicsApp$
[trace] Stack trace suppressed: run last compile:fastOptJS for the full output.
[error] (compile:fastOptJS) There were linking errors
The same code (with adaptations in the main file) is working on the vanilla Scala project, why this error appears?
It appears because you use a JVM-only library. mongo-scala-driver is not published for Scala.js. It it were, you could use a %%% dependency to depend on the Scala.js version of that library, which would work with Scala.js. But you cannot use a JVM-only library in a Scala.js project.
(Conversely, you cannot use a Scala.js-only library in a Scala/JVM project, for example, scalajs-dom.)

Linker error in ScalaJS: "Referring to non-existent class"

I am getting a bunch of linker errors when trying to link to FastParse in a Scala project which I've just tried to build a ScalaJS web app in.
I added the ScalaJS dependency for FastParse into my build.sbt: here's approximately the relevant line (full file here):
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "fastparse" % "0.4.1"
)
My errors are voluminous, but here's a representative one:
[error] Referring to non-existent class fastparse.Implicits$Repeater$
[error] called from parsers.MainParser$$anonfun$impls$1.apply()fastparse.core.Parser
[error] called from parsers.MainParser$$anonfun$impls$1.apply()java.lang.Object
[error] called from scala.Option.getOrElse(scala.Function0)java.lang.Object
[error] called from fastparse.StringReprOps$.errorMessage(fastparse.utils.ParserInput,java.lang.String,scala.Int)java.lang.String
[error] called from fastparse.core.ParseError.<init>(fastparse.core.Parsed$Failure)
[error] called from fastparse.Api.<init>(scala.reflect.ClassTag,fastparse.utils.ElemSetHelper,fastparse.utils.ReprOps,scala.math.Ordering)
[error] called from fastparse.StringApi.<init>()
[error] called from fastparse.all$.<init>()
[error] called from parsers.MainParser$.<init>()
[error] called from webapp.WebApp$.makeChoices(java.lang.String,java.lang.String)scala.collection.immutable.List
[error] called from webapp.WebApp$.$$js$exported$meth$makeChoices(java.lang.String,java.lang.String)java.lang.Object
[error] called from webapp.WebApp$.makeChoices
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] parsers.MainParser$$anonfun$impls$1
[error] scala.None$
[error] scala.Some
[error] fastparse.StringReprOps$
[error] webapp.WebApp$
What am I doing wrong?
The problem was that I was requiring the JVM version of FastParse two lines up in my build.sbt. This broke my build apparently. I removed that line and cleaned my build and now both the ScalaJS and ScalaJVM versions of the project are building nicely.
(Thanks heaps to Li Haoyi for spotting the problem for me)

Bad Symbolic reference to reactivemongo.api.collections.GenericHandlers encountered in class file 'JSONGenericHandlers.class'

I'm having my apis in play 2.3 with reactive mongo. Recently, i tried to cleaned the project and during the process, some things got updated. Later, when i tried to run or compile that, i'm getting these errors. Apart from clean, i didn't do anything. Kindly help me.
[info] Compiling 48 Scala sources and 1 Java source to /home/Ruthvick/zcapi/zceapi /target /scala-2.11/classes...
[error] bad symbolic reference to reactivemongo.api.collections.GenericHandlers encountered in class file 'JSONGenericHandlers.class'.
[error] Cannot access type GenericHandlers in package reactivemongo.api.collections. The current classpath may be
[error] missing a definition for reactivemongo.api.collections.GenericHandlers, or JSONGenericHandlers.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[error] /home/Ruthvick/zcapi/zceapi/app/controllers/Application.scala:28: type arguments [play.modules.reactivemongo.json.collection.JSONCollection] do not conform to method collection's type parameter bounds [C <: reactivemongo.api.Collection]
[error] def collection: JSONCollection = db.collection[JSONCollection]("shoppage")
[error] ^
[error] /home/Ruthvick/zcapi/zceapi/app/controllers/Application.scala:47: could not find implicit value for parameter writer: GenericCollection.this.pack.Writer[play.api.libs.json.JsObject]
[error] collection.insert(result).map { lastError =>
[error] ^
[error] 60 errors found
[error] (compile:compile) Compilation failed
[error] application -
Thanks,
Your version of Play is not compatible with the newest Snapshot of Play Reactive Mongo. You could just use Version 0.10.5.
Add this to your Library Dependencies
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"

Error using Mockito and Specs2

I have the following spec:
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
class LinkUserServiceSpec extends Specification with Mockito {
val linkUserService = mock[LinkUserService]
"The 'LinkUserService' isUserLinked method" should {
"return false when a previously unlinked userId is passed in for a given service" in {
linkUserService.isUserLinked("nobody", "YT") returns false
linkUserService.isUserLinked("nobody", "YT") must beFalse
}
}
}
And the following dependency in my build.sbt:
"org.specs2" %% "specs2" % "2.2" % "test"
However I get this error when I type test into the sbt console:
[error] bad symbolic reference. A signature in MocksCreation.class refers to type MockSettings
[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 MocksCreation.class.
[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.
[error] two errors found
[error] (test:compile) Compilation failed
[error] Total time: 3 s, completed Sep 12, 2013 3:23:41 PM
Anyone know what this could be?
Apparently if you want to use Mockito with Specs2 you have to provide the dependency yourself, I added the following to my build.sbt and things started working:
"org.mockito" % "mockito-all" % "1.9.5"