Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my sbt project dependency work? (insists on trying to fetch it remotely)

Tags:

sbt

scala.js

I'm wanting to have a bridge for Scala.js and Snap.svg in an sbt project, but also including demo code for the bridge.

When doing demos/compile sbt starts to say that it cannot resolve the dependency. It looks like it's trying to reach the bridge as if it was a publicized, external project but it's right here, and it compiles.

What am I doing wrong?

Removing the publishing-specific files does not seem to bring a change.

Directory structure:

├── build.sbt
├── project
│   ├── (PublishToBintray.scala)
│   ├── build.properties
│   ├── build.sbt
│   ├── project
│   │   └── ...
│   └── target
│   │   └── ...
├── (publishing.sbt)
├── scalajs_demos
│   ├── main
│   │   └── scala
│   │       └── clock.scala
│   └── target
│       └── ...
├── src
│   └── main
│       └── scala
│           └── org
│               └── scalajs
│                   └── snapsvg
│                       ├── SnapSvg.scala
│                       └── package.scala
└── target
    └── ...

build.sbt:

scalaJSSettings

name := "Scala.js Snap.svg"

normalizedName := "scalajs-snapsvg"

version := "0.01"

organization := "org.scala-lang.modules.scalajs"

scalaVersion := "2.11.1"

crossScalaVersions := Seq("2.10.4", "2.11.1")   // note: not tested with 2.10.x

libraryDependencies +=
  "org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6"   // TBD: probably need it, just like jQuery bridge does

ScalaJSKeys.jsDependencies +=
  "org.webjars" % "Snap.svg" % "0.3.0" / "snap.svg.js"

homepage := Some(url("http://snapsvg.io/"))

licenses += ("Apache 2.0", url("https://github.com/adobe-webplatform/Snap.svg/blob/master/LICENSE"))

//---
// bridge (main) project
//
lazy val bridge = project.in( file(".") )

//---
// demos project
//
lazy val demos = project.in( file("scalajs_demos") ).dependsOn(bridge)

What goes wrong in sbt:

> demos/compile
[info] Updating {file:/Users/asko/Hg/scala-js-snapsvg/}demos...
[info] Resolving org.scala-lang.modules.scalajs#scalajs-snapsvg_sjs0.5_2.10;0.01 ...
[warn]  module not found: org.scala-lang.modules.scalajs#scalajs-snapsvg_sjs0.5_2.10;0.01
[warn] ==== local: tried
[warn]   /Users/asko/.ivy2/local/org.scala-lang.modules.scalajs/scalajs-snapsvg_sjs0.5_2.10/0.01/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/scala-lang/modules/scalajs/scalajs-snapsvg_sjs0.5_2.10/0.01/scalajs-snapsvg_sjs0.5_2.10-0.01.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scala-lang.modules.scalajs#scalajs-snapsvg_sjs0.5_2.10;0.01: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last demos/*:update for the full output.
[error] (demos/*:update) sbt.ResolveException: unresolved dependency: org.scala-lang.modules.scalajs#scalajs-snapsvg_sjs0.5_2.10;0.01: not found
[error] Total time: 0 s, completed 27.7.2014 22:57:22
> 

One more thing, the project/plugins.sbt:

addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.0")
like image 430
akauppi Avatar asked Dec 25 '22 06:12

akauppi


1 Answers

The root cause of your issue is that the bridge project uses scalaVersion := "2.11.1" (as specified by your build.sbt, but your demos project uses the default scalaVersion (which is 2.10.2 in sbt 0.13, IIRC). The dependsOn relation gets confused when it tries to relate projects with different scalaVersions. See this issue: https://github.com/sbt/sbt/issues/1448

You probably thought that scalaVersion := "2.11.1" in the root build.sbt would apply to all subprojects. But that's not true, it only applies to the subproject rooted in . (here, bridge). You have to also specify this setting (and others you want shared) either as arguments of the settings() method of demos, or in the scalajs_demos/build.sbt file.

like image 163
sjrd Avatar answered Jan 05 '23 16:01

sjrd