0

I have a project with a bunch of tests written for Scalatest 1.x, which use the ShouldMatchers class, which was deprecated in version 2.x. Going forward, I want to use version 2 for new tests, but this will mean I have to refactor all my existing tests (which I can do, but it'll take some time).

In the meantime, is there a way in SBT to compile existing classes against Scalatest 1.x, and new ones against Scalatest 2.0?

Or more generally, compile some classes in a project against a different version of a library to other classes? (I'm aware that this might be quite a horrible idea.)

Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
  • I think this will mess up the class-path. Can't you just create two sub-projects for the two types of tests? – 0__ Apr 26 '16 at 09:53
  • in the same project? you can't. only in different projects. You could have some trouble with ides like IntelliJ though – Giovanni Caporaletti Apr 26 '16 at 09:53
  • The very issue is not a IDE one, but a classpath one, aka dependency hell – cchantep Apr 26 '16 at 10:04
  • @0__ Possibly, if that's the way to go. My SBT-fu is weak, so that would probably be a good exercise. Thanks for your answer below. I'll give it a try. – Luigi Plinge Apr 26 '16 at 10:08
  • @cchantep You're probably right, but I'm entertaining the possibility that as a build tool that is good at sorting out dependency hell, sbt might have some way to deal with this situation. Or it might not... that's my question. – Luigi Plinge Apr 26 '16 at 10:15
  • You can "shade" one version of the dependency, but in the end it's a workaround, not a transparent fix (needs to update some imports imports in the code) – cchantep Apr 26 '16 at 11:26

1 Answers1

3

You could create two dependent sub-projects, one for each version of scala-test.

lazy val root = project.in(file("."))

lazy val oldTests = project.in(file("old-tests"))
  .dependsOn(root)
  .settings(
    libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test"
  )

lazy val newTests = project.in(file("new-tests"))
  .dependsOn(root)
  .settings(
    libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"
  )
0__
  • 66,707
  • 21
  • 171
  • 266