I have the following in my predef.sc file and when I load Ammonite via my terminal, it fails for one library, the joda-time:
import $ivy.`org.typelevel::cats-core:2.1.1`, cats._, cats.implicits._
import $ivy.`org.scalatest::scalatest:3.0.8`,org.scalatest._
import $ivy.`org.scalacheck::scalacheck:1.14.0`
import $ivy.`io.monix::monix:3.1.0`
import $ivy.`dev.zio::zio:1.0.0-RC18`
import $ivy.`com.github.nscala-time::nscala-time:2.26.0`
import $ivy.`org.typelevel::cats-effect:2.1.2`
import $ivy.`com.github.chocpanda::scalacheck-magnolia:0.3.1`
import $ivy.`io.chrisdavenport::cats-scalacheck:0.2.0`
import $ivy.`net.ruippeixotog::scala-scraper:2.2.0`
import $ivy.`com.softwaremill.sttp.client3::core:3.1.9`
import $ivy.`joda-time::joda-time:2.10.14`
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.Future
import scala.util.{Failure, Success}
import scala.concurrent.Await
import monix.eval.Task
import org.scalacheck.{Arbitrary, Gen}
import com.github.nscala_time.time.Imports.DateTime
import com.github.nscala_time.time.Imports.DateTimeFormat
import org.scalacheck.magnolia._
import net.ruippeixotog.scalascraper.browser.JsoupBrowser
import net.ruippeixotog.scalascraper.dsl.DSL._
import net.ruippeixotog.scalascraper.dsl.DSL.Extract._
import net.ruippeixotog.scalascraper.dsl.DSL.Parse._
import sttp.client3._
import monix.reactive.Observable
import monix.execution.Ack.Continue
import monix.execution.{Ack, Scheduler}
import monix.reactive.observers.Subscriber
import monix.execution.Scheduler.Implicits.global
import org.joda.time.{DateTime, Days, Interval, Weeks}
import scala.math.Integral.Implicits._
The actual error message:
joesan#joesan-S-14-v5:~$ amm
Loading...
Failed to resolve ivy dependencies:Error downloading joda-time:joda-time_2.13:2.10.14
not found: /home/joesan/.ivy2/local/joda-time/joda-time_2.13/2.10.14/ivys/ivy.xml
not found: https://repo1.maven.org/maven2/joda-time/joda-time_2.13/2.10.14/joda-time_2.13-2.10.14.pom
I got it resolved by adding a dependency to the nscala-time as below:
import $ivy.`com.github.nscala-time::nscala-time:2.30.0`
import com.github.nscala_time.time.Imports._
Not sure why this was able to resolve while the joda-time not!
Related
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import io.cucumber.java.en.*;
#RunWith(CucumberOptions.class)
#CucumberOptions(features="resources/feature", glue="step")
public class Runner
{
}
Completely new to Cassandra. Tried to initialize a database in Cassandra using phantom-dsl. I received this error message.
*** RUN ABORTED ***
java.lang.AssertionError: assertion failed: no symbol could be loaded from class com.datastax.driver.core.Cluster in package core with name Cluster and classloader sun.misc.Launcher$AppClassLoader#279f2327
at scala.reflect.runtime.JavaMirrors$JavaMirror.scala$reflect$runtime$JavaMirrors$JavaMirror$$classToScala1(JavaMirrors.scala:1021)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:980)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:980)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$toScala$1.apply(JavaMirrors.scala:97)
at scala.reflect.runtime.TwoWayCaches$TwoWayCache$$anonfun$toScala$1.apply(TwoWayCaches.scala:39)
at scala.reflect.runtime.Gil$class.gilSynchronized(Gil.scala:19)
at scala.reflect.runtime.JavaUniverse.gilSynchronized(JavaUniverse.scala:16)
at scala.reflect.runtime.TwoWayCaches$TwoWayCache.toScala(TwoWayCaches.scala:34)
at scala.reflect.runtime.JavaMirrors$JavaMirror.toScala(JavaMirrors.scala:95)
at scala.reflect.runtime.JavaMirrors$JavaMirror.classToScala(JavaMirrors.scala:980)
I am not really sure whether it is an issue with the Connector in phantom-dsl or the ClusterBuilder in datastax-driver.
Connector.scala
package com.neruti.db
import com.neruti.db.models._
import com.websudos.phantom.database.Database
import com.websudos.phantom.connectors.ContactPoints
import com.websudos.phantom.dsl.KeySpaceDef
object Connector {
val host= Seq("localhost")
val port = 9160
val keySpace: String = "nrt_entities"
// val inet = InetAddress.getByName
lazy val connector = ContactPoints(host,port).withClusterBuilder(
_.withCredentials("cassandra", "cassandra")
).keySpace(keySpace)
}
CassandraSpec.scala
package com.neruti.db
import com.neruti.User
import com.neruti.db.models._
import com.neruti.db.databases._
import com.neruti.db.services._
import com.neruti.db.Connector._
import java.util.UUID
import com.datastax.driver.core.ResultSet
import org.scalatest._
import org.scalatest.{BeforeAndAfterAll,FlatSpec,Matchers,ShouldMatchers}
import org.scalatest.concurrent.ScalaFutures
import org.scalamock.scalatest.MockFactory
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
abstract class BaseCassandraSpec extends FlatSpec
with BeforeAndAfterAll
with Inspectors
with Matchers
with OptionValues
with ScalaFutures
class CassandraTest extends BaseCassandraSpec
with ProductionDatabase
with UserService
with Connector.connector.Connector{
val user = User(
Some("foobar"),
Some("foo#foobar.com"),
Some(UUID.randomUUID()),
)
override protected def beforeAll(): Unit = {
Await.result(database.userModel.create(user),10.seconds)
}
}
Looks there may be multiple issues you are looking at:
The latest version of phantom is 2.1.3, I'd strongly recommend using that, especially if you are just starting out. The migration guide is here in case you need it.
The entire reflection mechanism has been replaced in the latest version, so that error should magically go away. With respect to testing and generating objects, I would also look to include com.outworkers.util.testing, which is freely available on Maven Central
libraryDependencies ++= Seq(
//..,
"com.outworkers" %% "phantom-dsl" % "2.1.3",
"com.outworkers" %% "util-testing" % "0.30.1" % Test
)
This will offer you automated case class generation:
import com.outworkers.util.testing._
val sample = gen[User]
I am getting this error after migrating to 2.4 from 2.3. What is the right import statement I should use?
error: value routesImport is not a member of object play.Play.autoImport.PlayKeys
PlayKeys.routesImport += "se.radley.plugin.salat.Binders._",
I have these import statements:
import sbt._
import Keys._
import play.Play.autoImport._
import PlayKeys._
import WebKeys._
Should be like this:
import play.sbt.routes.RoutesKeys
...
RoutesKeys.routesImport += "se.radley.plugin.salat.Binders._"
I´m developing a Play Framework project in Scala, but I not able to get correctly the import controllers.Application reference.
The snippet bellow focus on the onStart method at my Global.scala file, that is located inside the app directory. What is going under the hood? Why can´t I get this easy import done correctly?
import play.api._
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.concurrent._
import play.api.Play.current
import scala.concurrent.duration._
import scala.util.Random
import model.StatusUpdate
object Global extends GlobalSettings {
override def onStart(app: Application) {
import controllers.{Application => App}
// Definition of the onStart method.
}
My Application.scala file that is located in the controllers directory is defined as bellow:
package controllers
import play.api._
import play.api.libs.iteratee._
import play.api.libs.json._
import play.api.mvc._
object Application extends Controller {
//Definition of methods
}
I'm trying to get my first Scala + Play! application working, and I encounter this problem when trying to access my application (on port 9000) :
not found: type Promise
on this line:
val page: Promise[play.api.libs.ws.Response] = WS.url(googleApiUrl).get()
Those are my imports:
import play.api._
import play.api.mvc._
import play.api.libs.ws._
import play.api.libs.ws.Response
import play.api.http
import play.api.libs.concurrent._
import play.api.libs._
Am I missing something here ?
Those are logs on the console:
sbt.PlayExceptions$CompilationException: Compilation error[not found: type Promise]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:322) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:322) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:322) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:319) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
Play2.1 use Scala Future instead of play Promise.
Check the migration guide for more informations, chapter "Play's Promise to become Scala's Future".
A simple exemple give something like that :
import play.api._
import play.api.mvc._
import play.api.libs.ws._
import play.api.libs.concurrent._
import play.api.libs.concurrent.Execution.Implicits._
def myAction() = Action {
Async {
WS.url(googleApiUrl).get.map(response => Ok("what you want here"))
}
}
You can check this exemple with a more complexe use of WS api.
The problem was with missing import:
import scala.concurrent._