Tim Barrass bio photo

Tim Barrass

Freelance C# and distributed systems developer.

Email Twitter LinkedIn Github Stackoverflow

Having to deal with versioned dependencies has been a rude wake-up call with Scala. It seemed simple: the scalajs-react library setup guide shows you how to fold it in:

libraryDependencies += "com.github.japgolly.scalajs-react" %%% "core" % "0.11.2"

but, sadly, no joy

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.github.japgolly.scalajs-react#core_sjs0.6_2.10;0.11.2: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

Ok. So where do I find this thing?

Finding scalajs-react

I had no idea. I had only a couple of repositories configured – https://jcenter.bintray.com and https://repo.typesafe.com/typesafe/ivy-releases/, and it clearly wasn’t finding them there – even if I used a browser to root around at those addresses.

Having no idea, I googled “maven scalajs-react” and immediately came to something that looked like a repository (but wasn’t) but did seem to be aware of scalajs-react: mvnrepository. I tried setting that as my repo in a few dumb ways, with no joy.

Rooting around on mvnrepository it looked like I could query information about core and other releases, getting as far as here and realising that it actually detailed repository locations – like central.maven.org. That looked more like it, and by digging around there I could find what looked like the packages I needed.

Getting hold of it - but not

I’m using Artifactory as a local offline cache as I do a lot of work on the train with an intermittent connection. It works fine, if you understand how the dependency resolution mechanism works. Turns out I didn’t. In Artefactory I added central.maven.org as a new remote repository, keyed as sbt-maven and updated my .sbt\repositories file, and attempted to rebuild.

Still without joy – SBT was attempting to download 0.6_2.10, and couldn’t find it. I did find that you could add a “from …” extension to the libraryDependencies setting, and that seemed to do the job, at least partly: it seemed to bypass Artefactory, and I didn’t really understand whether it was really working.

Realisation dawns

I asked StackOverflow, and although I didn’t get an answer, I did get some inspiration. sschaef pointed out that I couldn’t use a 2.11 library with Scala 2.10.

What?

Oh: it’s looking for 0.6_2.10 … and only core_sjs0.6_2.11 appears in the repository. The detail after the underscore probably represents the Scala version. Is that by convention, or something more structured? And why is it choosing 0.6?

I assume it’s 0.6 because that’s the latest version. There didn’t seem to be any 0.6 versions for 2.10, although there was a 0.5 – but nowhere could I specify 0.6 or 0.5. So I upgraded the Scala for the project to 2.11 – and everything worked.

Actually, more accurately I upgraded to 2.11 and modified the libraryDependencies call:

libraryDependencies += "com.github.japgolly.scalajs-react" %%% "core_sjs0.6_2.11" % "0.11.2"

and finally, having gradually found my way there, I found that mvnrepository actually tells you which setting to use to get hold of it:

// https://mvnrepository.com/artifact/com.github.japgolly.scalajs-react/core_sjs0.6_2.11
libraryDependencies += "com.github.japgolly.scalajs-react" % "core_sjs0.6_2.11" % "0.11.2"

which, hopefully I’ll remember for next time.