Accepted answer

You should replace the %% (double percent) with single one.

libraryDependencies += "org.apache.pdfbox" % "pdfbox" % "1.8.2"

The double-percent is a convenience operator, and causes adding the _+scalaVersion postfix inside the path, which is _2.10 in your case. Single percent should fix the problem.


Short answer:


libraryDependencies += "org.apache.pdfbox" % "pdfbox" % "1.8.2"

For java libraries, and

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"

For Scala libraries, where the difference is the double % for the scala library.

Long answer:

Scala is not backward compatible across major version, so a library compiled for scala 2.12.x cannot be used by a project written in scala 2.13.x.

So when writing a scala library, you will need to compile and publish it one time per scala major version you would like to support. When using a library in a project, you would then have to pick the version compiled for the same Scala major version as your are using. Doing this manually would be cumbersome, so SBT has built in support for it.

When publishing a library, you can add the crossScalaVersions key to SBT like

crossScalaVersions := Seq( "2.10.6", "2.11.11", "2.12.3" )

And then publish with sbt +publish. This will make SBT build and publish a version of the library for both scala 2.10.6, 2.11.11 and 2.12.3. Note that the minor number is in-relevant, when it comes to compatibility for libraries. The published libraries, will have the name suffixed with _2.10, _2.11 and _2.12 to show what scala version it is for. An alternative to using the SBT build in support for this, is to use the experimental plugin sbt-projectmatrix as this gives a lot more options, and often faster builds.

When using a library sbt can also help your use the one compiled for the correct scala version, and thats where %% comes into play. When specifying a library without the _ suffix in the name, but instead use %%, then sbt will fill in suffix matching the Scala major version your use, and thereby fetch the correct version of the library.

Related Query

More Query from same tag