Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created June 24, 2020 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmizu/86942c98b8275c8af84fd70a835babe5 to your computer and use it in GitHub Desktop.
Save kmizu/86942c98b8275c8af84fd70a835babe5 to your computer and use it in GitHub Desktop.
NoSuchMethodError occurs in (Scala 2.12.x or 2.13.x) and ScalaTest 3.1.x with scalikejdbc
import com.typesafe.config.ConfigFactory
name := "scalikejdbc-problem"
organization := "com.github.kmizu"
version := "0.0.1-SNAPSHOT"
val scalikejdbcVersion = "3.4.2"
val conf = ConfigFactory.parseFile(new File("src/main/resources/application.conf"))
lazy val commonSetting = Seq(
scalaVersion := "2.13.2",
libraryDependencies ++= Seq(
guice,
jdbc,
"com.h2database" % "h2" % "1.4.200",
"org.scalatest" %% "scalatest" % "3.1.2" % "test",
// "org.scalatest" %% "scalatest" % "3.0.8" % "test", // OK
"org.scalikejdbc" %% "scalikejdbc" % scalikejdbcVersion
)
)
lazy val root = (project in file("."))
.settings(commonSetting)
.settings(
parallelExecution in Test := false,
flywayUrl := conf.getString("db.default.url"),
flywayUser := "",
flywayPassword := "",
flywayLocations := Seq(
"filesystem:./conf/flyway/sql"
),
flywayUrl in Test:= conf.getString("test.db.default.url"),
flywayUser in Test:= "",
flywayPassword in Test:= "",
flywayLocations in Test:= Seq(
"filesystem:./conf/flyway/sql"
),
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.8.0-scalikejdbc-3.4",
"org.scalikejdbc" %% "scalikejdbc-config" % scalikejdbcVersion,
"org.scalikejdbc" %% "scalikejdbc-test" % scalikejdbcVersion % "test",
"org.scalikejdbc" %% "scalikejdbc-syntax-support-macro" % scalikejdbcVersion,
"com.querydsl" % "querydsl-scala" % "4.1.4"
)
)
[info] ReservationRepositorySpec:
[info] scalikejdbc
[info] ReservationRepositorySpec *** ABORTED ***
[info] java.lang.NoSuchMethodError: 'org.scalatest.Outcome scalikejdbc.scalatest.AutoRollback.withFixture$(scalikejdbc.scalatest.AutoRollback, org.scalatest.FixtureTestSuite$OneArgTest)'
[info] at ReservationRepositorySpec.withFixture(ExampleSpec.scala:7)
[info] at org.scalatest.funspec.FixtureAnyFunSpecLike.invokeWithFixture$1(FixtureAnyFunSpecLike.scala:502)
[info] at org.scalatest.funspec.FixtureAnyFunSpecLike.$anonfun$runTest$1(FixtureAnyFunSpecLike.scala:513)
[info] at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
[info] at org.scalatest.funspec.FixtureAnyFunSpecLike.runTest(FixtureAnyFunSpecLike.scala:513)
[info] at org.scalatest.funspec.FixtureAnyFunSpecLike.runTest$(FixtureAnyFunSpecLike.scala:494)
[info] at org.scalatest.funspec.FixtureAnyFunSpec.runTest(FixtureAnyFunSpec.scala:231)
[info] at org.scalatest.funspec.FixtureAnyFunSpecLike.$anonfun$runTests$1(FixtureAnyFunSpecLike.scala:557)
[info] at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
[info] at scala.collection.immutable.List.foreach(List.scala:333)
[info] ...
[error] java.lang.NoSuchMethodError: 'org.scalatest.Outcome scalikejdbc.scalatest.AutoRollback.withFixture$(scalikejdbc.scalatest.AutoRollback, org.scalatest.FixtureTestSuite$OneArgTest)'
[error] at ReservationRepositorySpec.withFixture(ExampleSpec.scala:7)
[error] at org.scalatest.funspec.FixtureAnyFunSpecLike.invokeWithFixture$1(FixtureAnyFunSpecLike.scala:502)
[error] at org.scalatest.funspec.FixtureAnyFunSpecLike.$anonfun$runTest$1(FixtureAnyFunSpecLike.scala:513)
[error] at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
[error] at org.scalatest.funspec.FixtureAnyFunSpecLike.runTest(FixtureAnyFunSpecLike.scala:513)
[error] at org.scalatest.funspec.FixtureAnyFunSpecLike.runTest$(FixtureAnyFunSpecLike.scala:494)
[error] at org.scalatest.funspec.FixtureAnyFunSpec.runTest(FixtureAnyFunSpec.scala:231)
import org.scalatest.BeforeAndAfterAll
import org.scalatest.fixture.FunSpec
import scalikejdbc.{DB, _}
import scalikejdbc.config.DBs
import scalikejdbc.scalatest.AutoRollback
class ReservationRepositorySpec extends FunSpec with AutoRollback with BeforeAndAfterAll {
//テスト実行前にダミーデータを追加
override def beforeAll(): Unit = {
DBs.setupAll()
DB autoCommit { implicit session =>
println("Hello")
}
}
describe("scalikejdbc") {
it("cause Exception") {implicit session =>
assert(true)
}
}
}
@kmizu
Copy link
Author

kmizu commented Jun 24, 2020

The reason of this problem is that scalikejdbc 3.4.2 (latest) depends on ScalaTest 3.0.x and ScalaTest 3.1.x removes org.scalatest.fixture.TestSuite, which is referenced by scalatest 3.4.2

@kmizu
Copy link
Author

kmizu commented Jun 24, 2020

It seems that this problem is fixed at scalilkejdbc 3.5.0-SNAPSHOT https://github.com/scalikejdbc/scalikejdbc/blob/master/build.sbt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment