Michael W.
Michael W.

Reputation: 391

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

Upvotes: 1

Views: 319

Answers (1)

susuro
susuro

Reputation: 36

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.

Upvotes: 2

Related Questions